ios开发之--简单动画效果的添加
2017-09-03 00:23
375 查看
记录一个简单的动画效果,自己写的,很简单,仅做记录。
附一个demo的下载地址:
https://github.com/hgl753951/hglTest.git
代码如下:
1,准备
2,具体代码
效果如下:
附一个demo的下载地址:
https://github.com/hgl753951/hglTest.git
代码如下:
1,准备
BOOL _isOpen; NSMutableArray * _btnArray;
2,具体代码
-(void)initUI { _btnArray = [[NSMutableArray alloc]init]; for (int i=0; i<4; i++) { UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom]; btn.tag = i; btn.frame = CGRectMake(260, 420, 40, 40); [btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"c_setting%d",(i+1)%4]] 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 = 0; i < _btnArray.count; i++) { UIButton * myBtn = [_btnArray objectAtIndex:i]; [UIView animateWithDuration:0.3 animations:^{ myBtn.frame = CGRectMake(190+(i%2)*70, 350+70*(i/2), 40, 40); } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 animations:^{ myBtn.frame = CGRectMake(200+(i%2)*60, 360+(i/2)*60, 40, 40); }]; }]; } } else { //关闭九宫格 for (int i = 0; i < _btnArray.count; i++) { UIButton * myBtn = [_btnArray objectAtIndex:i]; [UIView animateWithDuration:0.3 animations:^{ myBtn.frame = CGRectMake(190+(i%2)*70, 350+70*(i/2), 40, 40); } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 animations:^{ myBtn.frame = CGRectMake(260, 420, 40, 40); }]; }]; } } _isOpen = !_isOpen; }
效果如下:
相关文章推荐
- iOS开发-给TableView或者CollectionView的cell添加简单动画,很方便,直接粘代码即可
- 【iOS开发系列】简单动画效果
- iOS开发——添加动画效果、图片桢播放、时间器
- iOS开发——仿淘宝添加到购物车的动画效果实现
- IOS开发-CGAffineTransform的用法,实现一些简单动画效果
- ios开发之简单实现loading动画效果
- iOS 开发中问题 ——使用xib拖拽控件操作其约束并添加动画没有效果的问题
- iOS添加到购物车的简单动画效果
- iOS添加到购物车的简单动画效果
- ios开发之简单实现loading动画效果
- iOS开发仿淘宝添加到购物车的动画效果实现
- ios开发之简单实现loading动画效果
- iOS开发之各种动画各种页面切面效果
- iOS开发UI篇—iOS开发中三种简单的动画设置
- 【iOS开发-113】在storyboard上用AutoLayout,纯代码实现AutoLayout布局方法以及简单动画
- ios开发 各种动画效果
- iOS开发-UIView之动画效果的实现方法(合集)
- android 给LinearLayout中添加一定数量的控件,并让着一定数量的控件从右到左移动,每隔若干秒停顿一下,最后一个view链接第一个view,然后继续移动循环往复,形成一个死循环简单动画效果
- 【移动开发】为ViewGroup的子视图添加动画效果
- iOS开发中三种简单的动画设置