详解iPhone开发中各种动画实现效果

移动开发 iOS
本文介绍的是iPhone开发中各种动画实现效果。iphone中存在很多好看的动画效果,用于页面的切换等。其中某些是apple私有的,据说私有的无法通过apple的审批,来看内容。

iPhone开发中各种动画实现效果是本文要介绍的内容,iphone中存在很多好看的动画效果,用于页面的切换等。其中某些是apple私有的,据说私有的无法通过apple的审批。最近工作中刚好用到过其中的某些动画,所以在网上搜了下资料,了解了下这些动画。这里就自己的理解做一下总结,如有错误或遗漏,尽请谅解。

1、UIView 动画

官方API中,使用UIView可以设置5个动画效果,分别为:

UIViewAnimationTransitionNone    不使用动画  
 
UIViewAnimationTransitionFlipFromLeft    从左向右旋转翻页  
 
UIViewAnimationTransitionFlipFromRight    从右向左旋转翻页,与UIViewAnimationTransitionFlipFromLeft相反  
 
UIViewAnimationTransitionCurlUp    卷曲翻页,从下往上  
 
UIViewAnimationTransitionCurlDown    卷曲翻页,从上往下  
 
详细请参见UIViewAnimationTransition 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

例子:

[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];//提交动画 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

2、公共动画效果

使用CATransiton可以设置4种动画效果,分别为:

NSString * const kCATransitionFade;//渐渐消失  
 
NSString * const kCATransitionMoveIn;//覆盖进入  
 
NSString * const kCATransitionPush;//推出  
 
NSString * const kCATransitionReveal;//与MoveIn相反 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

例子:

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"]; 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

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 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.

以上所有动画效果的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]; 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

其中setAnimationPosition方法就是用于设置缩小点的位置的,此处虽然会报一个警告,但是结果还是正确的。

小结:详解iPhone开发中各种动画实现效果的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 新浪博客
相关推荐

2011-08-10 14:40:23

iPhone动画

2011-07-08 10:15:15

IPhone 动画

2011-07-29 13:55:10

IPhone 动画

2011-08-16 18:13:42

IPhone开发UIView动画

2011-08-03 16:35:10

iPhone UIView 动画

2011-08-03 16:26:14

iPhone UIView 动画

2011-08-22 14:21:24

iPhone开发UIView Anim

2011-07-22 18:20:04

IOS View 动画

2011-07-08 15:08:16

iPhone 图片

2011-08-10 17:37:00

iPhoneASIHTTPRequ

2011-08-15 13:50:06

IPhone开发UIView动画

2018-10-10 09:00:00

前端框架Angular

2011-07-28 10:11:54

iPhone开发 备忘

2011-08-15 11:37:20

iPhone开发Mask

2011-08-12 14:33:06

iPhone缓存文件

2011-08-12 11:31:46

iPhoneUIView动画

2011-07-29 14:18:46

iPhone开发 动画

2011-08-15 15:44:46

iPhone开发PDF

2011-08-18 16:24:44

iPhone开发图片

2011-07-26 14:18:20

点赞
收藏

51CTO技术栈公众号