UIView实现动画效果
2015-08-21 15:00
501 查看
http://blog.sina.com.cn/s/blog_5da93c8f0101qmsc.html
UIView类的很多属性都设计为动画,动画的属性是指当属性从一个值变成另外一个值时可以支持动画,同时通知UIKit需要执行什么样类型的动画,UIView对象支持动画的属性有如下几个:
frame属性:可以使用该属性改变尺寸和位置
bounds:改变尺寸
center:改变视图的位置
alpha:改变视图的透明度
backgroundColor:改变视图的背景
contentStretch:改变视图内容如何拉伸
IOS封装了Core Animation来是实现动画,Core Animation的最大好处是可以帮助Mac或者iPhone的开发者减少代码量。因为如果你想用Core Image或者Open GL实现界面的动画特效,其实也是可以的,主要是非常麻烦。而用Core Animation可以极大简化开发难度和减少代码量,IOS提供的核心动画编程接口,可以让编程人员以非常简单的方式实现炫目流畅的动画效果
翻转的动画
//开始动画
[UIView beginAnimations:@"wap view" context:nil];
//设置时常
[UIView setAnimationDuration:1];
//设置动画淡入淡出
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//设置代理
[UIView setAnimationDelegate:self];
//设置翻转方向
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:manImageView cache:YES];
//动画结束
[UIView commitAnimations];
旋转动画
创建一个CGAffineTransform transform对象 CGAffineTransform transform;
//设置旋转度数
transform = CGAffineTransformRotate(manImageView.transform,M_PI/6.0);
//动画开始
[UIView beginAnimations:@"rotate" context:nil ];
//动画时常
[UIView setAnimationDuration:2];
//添加代理
[UIView setAnimationDelegate:self];
//获取transform的值
[manImageView setTransform:transform];
//关闭动画
[UIView commitAnimations];
偏移动画
[UIView beginAnimations:@"move" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self]; //改变它的frame的x,y的值 manImageView.frame=CGRectMake(100,100, 120,100);
[UIView commitAnimations];
翻页动画
[UIView beginAnimations:@"curlUp" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//指定动画曲线类型,该枚举是默认的,线性的是匀速的
//设置动画时常 [UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self]; //设置翻页的方向
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:manImageView cache:YES];
//关闭动画
[UIView commitAnimations];
缩放动画
CGAffineTransform transform;
transform = CGAffineTransformScale(manImageView.transform,1.2,1.2);
[UIView beginAnimations:@"scale" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
[manImageView setTransform:transform];
[UIView commitAnimations];
取反的动画效果是根据当前的动画取他的相反的动画
CGAffineTransform transform;
transform=CGAffineTransformInvert(manImageView.transform);
[UIView beginAnimations:@"Invert" context:nil];
[UIView setAnimationDuration:2];//动画时常
[UIView setAnimationDelegate:self];
[manImageView setTransform:transform];//获取改变后的view的transform [UIView commitAnimations];//关闭动画
UIView类的很多属性都设计为动画,动画的属性是指当属性从一个值变成另外一个值时可以支持动画,同时通知UIKit需要执行什么样类型的动画,UIView对象支持动画的属性有如下几个:
frame属性:可以使用该属性改变尺寸和位置
bounds:改变尺寸
center:改变视图的位置
alpha:改变视图的透明度
backgroundColor:改变视图的背景
contentStretch:改变视图内容如何拉伸
IOS封装了Core Animation来是实现动画,Core Animation的最大好处是可以帮助Mac或者iPhone的开发者减少代码量。因为如果你想用Core Image或者Open GL实现界面的动画特效,其实也是可以的,主要是非常麻烦。而用Core Animation可以极大简化开发难度和减少代码量,IOS提供的核心动画编程接口,可以让编程人员以非常简单的方式实现炫目流畅的动画效果
翻转的动画
//开始动画
[UIView beginAnimations:@"wap view" context:nil];
//设置时常
[UIView setAnimationDuration:1];
//设置动画淡入淡出
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//设置代理
[UIView setAnimationDelegate:self];
//设置翻转方向
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:manImageView cache:YES];
//动画结束
[UIView commitAnimations];
旋转动画
创建一个CGAffineTransform transform对象 CGAffineTransform transform;
//设置旋转度数
transform = CGAffineTransformRotate(manImageView.transform,M_PI/6.0);
//动画开始
[UIView beginAnimations:@"rotate" context:nil ];
//动画时常
[UIView setAnimationDuration:2];
//添加代理
[UIView setAnimationDelegate:self];
//获取transform的值
[manImageView setTransform:transform];
//关闭动画
[UIView commitAnimations];
偏移动画
[UIView beginAnimations:@"move" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self]; //改变它的frame的x,y的值 manImageView.frame=CGRectMake(100,100, 120,100);
[UIView commitAnimations];
翻页动画
[UIView beginAnimations:@"curlUp" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//指定动画曲线类型,该枚举是默认的,线性的是匀速的
//设置动画时常 [UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self]; //设置翻页的方向
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:manImageView cache:YES];
//关闭动画
[UIView commitAnimations];
缩放动画
CGAffineTransform transform;
transform = CGAffineTransformScale(manImageView.transform,1.2,1.2);
[UIView beginAnimations:@"scale" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
[manImageView setTransform:transform];
[UIView commitAnimations];
取反的动画效果是根据当前的动画取他的相反的动画
CGAffineTransform transform;
transform=CGAffineTransformInvert(manImageView.transform);
[UIView beginAnimations:@"Invert" context:nil];
[UIView setAnimationDuration:2];//动画时常
[UIView setAnimationDelegate:self];
[manImageView setTransform:transform];//获取改变后的view的transform [UIView commitAnimations];//关闭动画
相关文章推荐
- AsyncTask介绍
- UIView之userInteractionEnabled属性介绍
- hdu5412CRB and Queries(整体二分)
- WPF:如何在工作线程中更新窗体的UI元素(Dispatcher机制)
- UIView 的Transform。(旋转,缩放,3D旋转)
- UIScrollView
- 自定义UIPageControl 的Circle 与其他实现方式有几行代码改动,亲自试过
- iOS 3D UI---CALayer的transform扩展
- [LeetCode] Unique Paths
- forward与include转发问题(RequestDispatcher.include()(乱码问题分析及解决)
- Mix and Build(简单DP)
- Mix and Build(简单DP)
- UITextField详解
- 解决query不到本地视频方法
- 设置UIView的背景色和背景图片
- QT 总结(四) 1.中文编码 乱码 2.QFileDialog 打开文件框 3.调用其它UI文件 4.QMessageBox弹窗
- How To Build Compelling Stories From Your Data Sets
- HDU 1387 Team Queue(优先队列)
- 这里想经过一个小程序研究标准库为 vector 对象提供的内存分配策,因为vector容器比list和deque容器用的很多,而且它的存储方式是连续的
- 自定义UIAlertView及简单的回调函数使用说明