IOS中各种动画特效的实现

来源:互联网 发布:磅房软件 编辑:程序博客网 时间:2024/05/16 15:22
第一类动画特效:
这类特效有四种,在UIView中就可以实现,分别为CurlDown,CurlUp,FilpFromLeft,FilpFromRight。在视图切换之前设置UIView,如下:

   [UIViewbeginAnimations:@"Animation" context:nil];

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

   [UIView setAnimationDelegate:self];

   [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

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

 

[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDownforView:self.view cache:YES];

[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.view cache:YES];

[UIViewsetAnimationTransition:UIViewAnimationTransitionFilpFromLeft forView:self.viewcache:YES];

[UIViewsetAnimationTransition:UIViewAnimationTransitionFilpFromRight forView:self.viewcache:YES];

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

 

[UIView commitAnimations];


第二类动画特效:

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

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

 

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

   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:animationforKey:@"animation"];


0 0
原创粉丝点击