iOS应用开发之:常用三种动画表现效果
2015-10-29 15:57
801 查看
在iPhone开发中,我们常常需要在不同的页面之间做动画的切换,这样看起来更加好看。基本的动画有以下三种:
1.UIView
UIView官方提供五种动画效果供大家使用,分别为:
<font size="3" color="#000000">UIViewAnimationTransitionNone 不使用动画
UIViewAnimationTransitionFlipFromLeft 从左向右旋转翻页
UIViewAnimationTransitionFlipFromRight 从右向左旋转翻页,与UIViewAnimationTransitionFlipFromLeft相反
UIViewAnimationTransitionCurlUp 卷曲翻页,从下往上
UIViewAnimationTransitionCurlDown 卷曲翻页,从上往下</font>
例子:
<font size="3" color="#000000">[UIView beginAnimations:@"animationID" context:nil];//开始一个动画块,第一个参数为动画块标识
[UIView setAnimationDuration:0.5f];//设置动画的持续时间
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//设置动画块中的动画属性变化的曲线,此方法必须在beginAnimations方法和commitAnimations,默认即为UIViewAnimationCurveEaseInOut效果。详细请参见UIViewAnimationCurve
[UIView setAnimationRepeatAutoreverses:NO];//设置是否自动反转当前的动画效果
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//设置过渡的动画效果,此处第一个参数可使用上面5种动画效果
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//页面翻转
[UIView commitAnimations];//提交动画</font>
这样,我们就可以让UIView的页面通过动画实现页面之间的跳转。
2. CATransiton
CATransiton官方提供4种动画效果,分别为:
NSString * const kCATransitionFade;//渐渐消失
NSString * const kCATransitionMoveIn;//覆盖进入
NSString * const kCATransitionPush;//推出
NSString * const kCATransitionReveal;//与MoveIn相反
例子:
CATransition *animation = [CATransition animation];//初始化动画
animation.duration = 0.5f;//间隔的时间
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.type = kCATransitionPush;//设置上面4种动画效果
animation.subtype = kCATransitionFromTop;//设置动画的方向,有四种,分别为kCATransitionFromRight、kCATransitionFromLeft、kCATransitionFromTop、kCATransitionFromBottom
[self.view.layer addAnimation:animation forKey:@"animationID"];
3.私有动画私有动画是在UIView的基础上,设置animation.type,可以提供一下几种选择:cube:像立方体那样翻转suckEffect:渐渐缩小,与删除照片的动画一样oglFlip:上下旋转,当subType为fromLeft或者fromRight时,与UIViewAnimationTransitionFlipFromLeft和UIViewAnimationTransitionFlipFromRight一样rippleEffect:水波效果pageCurl:与UIViewAnimationTransitionCurlUp一样pageUnCurl:与UIViewAnimationTransitionCurlDown一样cameraIrisHollowOpen:First
half of cameraIris.cameraIrisHollowClose:Second half of cameraIris
1.UIView
UIView官方提供五种动画效果供大家使用,分别为:
<font size="3" color="#000000">UIViewAnimationTransitionNone 不使用动画
UIViewAnimationTransitionFlipFromLeft 从左向右旋转翻页
UIViewAnimationTransitionFlipFromRight 从右向左旋转翻页,与UIViewAnimationTransitionFlipFromLeft相反
UIViewAnimationTransitionCurlUp 卷曲翻页,从下往上
UIViewAnimationTransitionCurlDown 卷曲翻页,从上往下</font>
例子:
<font size="3" color="#000000">[UIView beginAnimations:@"animationID" context:nil];//开始一个动画块,第一个参数为动画块标识
[UIView setAnimationDuration:0.5f];//设置动画的持续时间
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//设置动画块中的动画属性变化的曲线,此方法必须在beginAnimations方法和commitAnimations,默认即为UIViewAnimationCurveEaseInOut效果。详细请参见UIViewAnimationCurve
[UIView setAnimationRepeatAutoreverses:NO];//设置是否自动反转当前的动画效果
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//设置过渡的动画效果,此处第一个参数可使用上面5种动画效果
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//页面翻转
[UIView commitAnimations];//提交动画</font>
这样,我们就可以让UIView的页面通过动画实现页面之间的跳转。
2. CATransiton
CATransiton官方提供4种动画效果,分别为:
NSString * const kCATransitionFade;//渐渐消失
NSString * const kCATransitionMoveIn;//覆盖进入
NSString * const kCATransitionPush;//推出
NSString * const kCATransitionReveal;//与MoveIn相反
例子:
CATransition *animation = [CATransition animation];//初始化动画
animation.duration = 0.5f;//间隔的时间
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.type = kCATransitionPush;//设置上面4种动画效果
animation.subtype = kCATransitionFromTop;//设置动画的方向,有四种,分别为kCATransitionFromRight、kCATransitionFromLeft、kCATransitionFromTop、kCATransitionFromBottom
[self.view.layer addAnimation:animation forKey:@"animationID"];
3.私有动画私有动画是在UIView的基础上,设置animation.type,可以提供一下几种选择:cube:像立方体那样翻转suckEffect:渐渐缩小,与删除照片的动画一样oglFlip:上下旋转,当subType为fromLeft或者fromRight时,与UIViewAnimationTransitionFlipFromLeft和UIViewAnimationTransitionFlipFromRight一样rippleEffect:水波效果pageCurl:与UIViewAnimationTransitionCurlUp一样pageUnCurl:与UIViewAnimationTransitionCurlDown一样cameraIrisHollowOpen:First
half of cameraIris.cameraIrisHollowClose:Second half of cameraIris
相关文章推荐
- iOS 8 AutoLayout与Size Class
- ios9中的提示框
- iOS如何给没有点击事件的View添加响应操作
- IOS 多线程 NSThread
- iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry)
- iOS Crash文件的解析
- ios jenkins 打包问题
- iOS性能调优
- iOS的socket开发基础
- iOS倒计时方法
- 【视频】高德开发者公开课—如何使用IOS SDK进行开发
- iOS 第三方白名单
- iOS开发内购全套图文教程
- Xcode7 开发 mob更替新版本短信验证sdk 出现 overrides method from class 问题解决
- iOS设计模式 - 单例模式
- 【HDOJ】【1017】A Mathematical Curiosity
- IOS中NSUserDefaults的用法(轻量级本地数据存储)
- iOS 静态库引用注意事项
- iOS一个应用有多个颜色主题时,用到图片的地方如何处理
- iOS 搜索栏的使用