记录一个简单的动画效果,自己写的,很简单,仅做记录。

附一个demo的下载地址:

https://github.com/hgl753951/hglTest.git

代码如下:

1,准备

BOOL _isOpen;
NSMutableArray * _btnArray;

2,具体代码

-(void)initUI
{
_btnArray = [[NSMutableArray alloc]init];
for (int i=; i<; i++)
{
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.tag = i;
btn.frame = CGRectMake(, , , );
[btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"c_setting%d",(i+)%]] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[_btnArray addObject:btn]; }
} -(void)btnClick:(UIButton *)btn
{
//如果没有打开
if (!_isOpen)
{
//打开九宫格
for (int i = ; i < _btnArray.count; i++)
{
UIButton * myBtn = [_btnArray objectAtIndex:i];
[UIView animateWithDuration:0.3
animations:^{
myBtn.frame = CGRectMake(+(i%)*, +*(i/), , );
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.3
animations:^{
myBtn.frame = CGRectMake(+(i%)*, +(i/)*, , );
}];
}];
} }
else
{
//关闭九宫格
for (int i = ; i < _btnArray.count; i++)
{
UIButton * myBtn = [_btnArray objectAtIndex:i];
[UIView animateWithDuration:0.3
animations:^{
myBtn.frame = CGRectMake(+(i%)*, +*(i/), , );
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.3
animations:^{
myBtn.frame = CGRectMake(, , , ); }];
}];
} }
_isOpen = !_isOpen;
}

效果如下:

ios开发之--简单动画效果的添加的更多相关文章

  1. iOS开发 QQ粘性动画效果

    QQ(iOS)客户端的粘性动画效果 时间 2016-02-17 16:50:00  博客园精华区 原文  http://www.cnblogs.com/ziyi--caolu/p/5195615.ht ...

  2. iOS开发之吸附动画效果

    步骤:1.使用singleviewapplication创建新的项目 2.在.h文件中创建两张图片的实例对象,并与相关的图片进行相连:创建一个UIDynamicAnimator实例对象 3.在.m文件 ...

  3. iOS 开发之推力动画效果

    步骤: 1.使用single view application 创建新的项目 2.在.h文件中需要遵守两个协议<UICollisionBehaviorDelegate,UIGestureReco ...

  4. iOS开发只简单动画实现

    1.动画旋转: [UIViewbeginAnimations:@"View Flip"context:nil]; //声明,@"XX"为标题, [UIViews ...

  5. iOS 开发之重力动画效果

    步骤:1.使用single view application创建新的项目 2.在viewcontroller.h文件中创建一个图片实例并与相关图片相连,然后创建一个UIDynamicAnimator ...

  6. IOS开发系列 --- 核心动画

    原始地址:http://www.cnblogs.com/kenshincui/p/3972100.html 概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥i ...

  7. iOS开发UI篇—在UIImageView中添加按钮以及Tag的参数说明

    ios开发UI篇—在ImageView中添加按钮以及Tag的参数说明 一.tag参数 一个视图通常都只有一个父视图,多个子视图,在开发中可以通过使用子视图的tag来取出对应的子视图.方法为Viewwi ...

  8. ios开发UI篇—在ImageView中添加按钮以及Tag的参数说明

    ios开发UI篇—在ImageView中添加按钮以及Tag的参数说明 一.tag参数 一个视图通常都只有一个父视图,多个子视图,在开发中可以通过使用子视图的tag来取出对应的子视图.方法为Viewwi ...

  9. 原生JS封装简单动画效果

    原生JS封装简单动画效果 一致使用各种插件,有时候对原生JS陌生了起来,所以决定封装一个简单动画效果,熟悉JS原生代码 function animate(obj, target,num){ if(ob ...

随机推荐

  1. 判断IP是否为爬虫IP

    方法一: 通过国外网站验证:http://bot.myip.ms/123.125.71.12 返回结果: IP/Domain - 123.125.71.12:   Baidu Bot on this ...

  2. HTML源文件编码的问题

    刚才使用sublime text编辑html文件,在html中使用meta tag指定了charset,如下 <meta http-equiv="content-type" ...

  3. calloc内存分配函数

    calloc是一个C语言函数 函数名: calloc void *calloc(unsigned n,unsigned size): 功 能: 在内存的动态存储区中分配n个长度为size的连续空间,函 ...

  4. C++14尝鲜:Generic Lambdas(泛型lambda)

    所谓泛型lambda.就是在形參声明中使用auto类型指示说明符的lambda. 比方 auto lambda = [](auto x, auto y) {return x + y;}; 依据C++1 ...

  5. Android——对话框1(一般、选择、自定义、进度条)

    xml <Button android:layout_width="match_parent" android:layout_height="wrap_conten ...

  6. MySql 生成日期随机数

    select DATE_ADD(sd, INTERVAL FLOOR(1+ RAND() * ((ABS(UNIX_TIMESTAMP(ed) - UNIX_TIMESTAMP(sd))) - 1)) ...

  7. C语言实现商品销售系统

    商品销售系统 #include<stdio.h> //头文件 #include<string.h> //头文件 #include<stdlib.h> //头文件 # ...

  8. java父子进程通信

    1.利用进程的管道通信传输流 2.子进程没有控制台,正常测试的时候也是没办法看到子进程的输出的,需要传到主线程 3.测试主进程传参给子进程再传回来 4.父进程启动子进程只要执行runtime.exec ...

  9. svg 添加超链接

    <svg>    <a xlink:href="http://www.w3.org//Graphics//SVG//Overview.htm8">      ...

  10. Java中Calendar.DAY_OF_WEEK需要减一的原因

    http://blog.sina.com.cn/s/blog_45c06e600100pm77.html ——————————————————————————————————————————————— ...