您的位置:首页 > 移动开发 > IOS开发

IOS中各种动画特效的实现

2015-12-23 09:27 615 查看
第一类动画特效:

这类特效有四种,在UIView中就可以实现,分别为CurlDown,CurlUp,FilpFromLeft,FilpFromRight。在视图切换之前设置UIView,如下:

[UIView
beginAnimations:@"Animation" context:nil];

[UIView setAnimationDuration:0.5];//设置动画持续时间;

[UIView setAnimationDelegate:self];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

接下来设置动画特效,有四种特效可供选择:

[UIView
setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view cache:YES];

[UIView
setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.view cache:YES];

[UIView
setAnimationTransition:UIViewAnimationTransitionFilpFromLeft forView:self.view
cache:YES];

[UIView
setAnimationTransition:UIViewAnimationTransitionFilpFromRight forView:self.view
cache:YES];

之后就可以切换view了,最后执行动画:

[UIView commitAnimations];

第二类动画特效:

这类动画特效需要用到QuartzCore.framework,单击工程,点击Build
Phases,找到Link Binary With
Libraries,点击下面的+号,找到QuartzCore.framework添加即可。

同样,在view切换之前需要做一些设置:

CATransition
*animation = [CATransition
animation]; //声明动画对象;

animation.delegate = self;

animation.duration = kDuration;//设置动画持续时间;

animation.timingFunction = UIViewAnimationCurveEaseInOut;

然后就可以选择动画类型,大概有十二种动画:

animation.type = kCATransitionFade;

animation.type = kCATransitionPush;

animation.type = kCATransitionReveal;

animation.type = kCATransitionMoveIn;

animation.type = @"cube";

animation.type = @"suckEffect";

animation.type = @"oglFlip";

animation.type = @"rippleEffect";

animation.type = @"pageCurl";

animation.type = @"pageUnCurl";

animation.type = @"cameraIrisHollowOpen";

animation.type = @"cameraIrisHollowClose";

任选其中一种。同时也可以设置animation的subtype,用以设置动画运行的方向,如:

animation.subtype
= kCATransitionFromLeft;

animation.subtype
= kCATransitionFromBottom;

animation.subtype
= kCATransitionFromRight;

animation.subtype
= kCATransitionFromTop;

之后是切换view,最后还要添加一句代码:

[[self.view layer] addAnimation:animation
forKey:@"animation"];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: