http://blog.csdn.net/xiaoguan2008/article/details/6291425
iphone中存在很多好看的动画效果,用于页面的切换等。其中某些是apple私有的,据说私有的无法通过apple的审批。
最近工作中刚好用到过其中的某些动画,所以在网上搜了下资料,了解了下这些动画。这里就自己的理解做一下总结,如有错误或遗漏,尽请谅解。
1、UIView 动画
官方API中,使用UIView可以设置5个动画效果,分别为:
UIViewAnimationTransitionNone 不使用动画
UIViewAnimationTransitionFlipFromLeft 从左向右旋转翻页
UIViewAnimationTransitionFlipFromRight 从右向左旋转翻页,与UIViewAnimationTransitionFlipFromLeft相反
UIViewAnimationTransitionCurlUp 卷曲翻页,从下往上
UIViewAnimationTransitionCurlDown 卷曲翻页,从上往下
详细请参见UIViewAnimationTransition
例子:
[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];//提交动画
2、公共动画效果
使用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、私有动画
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
以上所有动画效果的demo请见http://www.cocoachina.com/bbs/read.php?tid-11820.html,在此感谢楼主的分享,给我的学习带来很到的帮助。
UIViewAnimationState描述:http://www.iphonedevwiki.net/index.php/UIViewAnimationState
同时,本人在使用UIView实现suckEffect缩小的效果过程中遇到一个问题(不知道如何定位),经过搜索终觅得解决方法,分享如下:
[UIView beginAnimations:@"suck" context:NULL];
[UIView setAnimationTransition:103 forView:self.view cache:YES];
[UIView setAnimationDuration:0.5f];
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown) {
[UIView setAnimationPosition:CGPointMake(44, 42)];
}else {
[UIView setAnimationPosition:CGPointMake(320 , 42)];
}
[UIView commitAnimations];
其中setAnimationPosition方法就是用于设置缩小点的位置的,此处虽然会报一个警告,但是结果还是正确的。