iOS 中常用的动画效果
Iphone中存在很多好看的动画效果,用于页面的切换等。其中某些是apple私有的,据说私有的无法通过apple的审批。
最近工作中刚好用到过其中的某些动画,所以在网上搜了下资料,了解了下这些动画。这里就自己的理解做一下总结,如有错误或遗漏,尽请谅解。
1、UIView动画(基础简单类)
官方API中,使用UIView可以设置5个动画效果,分别为:
UIViewAnimationTransitionNone 不使用动画
UIViewAnimationTransitionFlipFromLeft 从左向右旋转翻页
UIViewAnimationTransitionFlipFromRight 从右向左旋转翻页,与UIViewAnimationTransitionFlipFromLeft相反
UIViewAnimationTransitionCurlUp 卷曲翻页,从下往上
UIViewAnimationTransitionCurlDown 卷曲翻页,从上往下
相关app代码;
[UIView beginAnimations:@"animationID" context:nil];//开始一个动画块,第一个参数为动画块标识
[UIView setAnimationDuration:0.5f];//设置动画的持续时间
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//设置动画块中的动画属性变化的曲线,此方法必须在beginAnimations方法和commitAnimations,默认即为UIViewAnimationCurveEaseInOut效果。
[UIView setAnimationRepeatAutoreverses:NO];//设置是否自动反转当前的动画效果
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//设置过渡的动画效果,此处第一个参数可使用上面5种动画效果
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];//页面翻转
[UIView commitAnimations];//提交动画
2 CATransiton类动画 (公用类)
使用CATransiton可以设置4种动画效果,分别为:
NSString * const kCATransitionFade;//渐渐消失
NSString * const kCATransitionMoveIn;//覆盖进入
NSString * const kCATransitionPush;//推出
NSString * const kCATransitionReveal;//与MoveIn相反
相关app代码;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、私有动画
iphone种还有很多动画是苹果私有的,例如删除照片的动画等,
私有动画可以直接在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