现在的位置: 首页 > 综合 > 正文

iOS学习阶段总结-b20120920-动画转场

2014年07月24日 ⁄ 综合 ⁄ 共 3787字 ⁄ 字号 评论关闭

iPhone动画类型:

1.UIView,可能在底层用CATransition进行了封装,它只能用于一些简单的常用的效果展现;

2.CATransition,相对复杂,是对UIView的Layer进行底层控制和动画操作。

UIView基本动画转场

第一类UIView类方法全局:

[UIView beginAnimations:nil context:NULL];

[UIView setAnimaitonCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:5.0f];

/*动作放在这里*/

[UIView commitAnimations];

淡进淡出:alpha变换

...

淡进:imgeView.alpha = 1.0f 淡出:iamgeView.alpha = 0.0f

...

位移:位置变换

view.frame  = CGRectMake(0.0f,0.0f,320.0f,44.0f);

...

view.frame = CGRectMake(0.0f,44.0f,320.0f,44.0f);

...

旋转变换

...

view.transform = CGAffineTransformMakeRotation(3.14/2.0);

...

核心方法:

+ (void)setAnimationDelegate:(id)delegate;//设置代理,缺省为nil

+ (void)setAnimationWillSelector:(SEL)selector;//设置动画开始时的调用方法,缺省为NULL

+ (void)setAnimationDidStopSelector:(SEL)selector;//设置动画停止时的调用方法,缺省为NULL

+ (void)setAnimationDuration:(NSTimerInterval)duration;//设置动画持续时间按,缺省是0.2秒

+ (void)setAnimationDelay:(NSTimeInterval)delay;//设置动画的开始时间(延迟时间),缺省是0.0

+ (void)setAnimationStartDate:(NSDate *)startDate;//设置动画的开启日期,缺省是NULL

+ (void)setAnimationCurve:(UIViewAnimationCurve)curve;//设置动画的方式,缺省是UIViewAnimationCurveEaseInOut;

+ (void)setAnimationRepeatCount:(float)repeatCount;//设置动画的重复次数,缺省是0

+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses;//设置动画完成后是否还原,结束后动态复原到最开始状态,缺省是NO

iOS4.0之后的Blocks动画

UIViewAnimationOptions options = UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction;

[UIView animateWithDuration:3.0f delay:0.0 options:options animations:^{} completion:^(BOOL finished){}];

核心方法;

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void(^)(void))animations completion:(void(^)(BOOL finished))completion;

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void(^)(void))animations completion:(void(^)(BOOL finished))completion;

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void(^)(void))animations;

第二类UIView动画

支持UIView翻页CurlUp/CurlDown

支持UIView翻转FlipFromLeft/FlipFromRight

翻页代码

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:5.0f];

[UIView setAnimationTransition:UIViewAnimationTransitionCulUp forView:parentView cache:YES];//设置parentView翻页动画

[parentView exchangeSubviewAtIndex:page1Index withSubviewAtIndex:page2Index];//把parentView中的page1和page2换一个位置

[UIView commitAnimations];

使用Block的翻页代码

UIViewAnimatinoOptions options = UIViewAnimationOptionTransitionCurlUp | UIViewAnimationOptionCurveEaseInOut;

[UIView transitionWithView:parentView

                         duration:3.0f options:options

                         animations:^{

                                 [parentView exchangeSubviewAtIndex:page1Index withSubviewAtIndex:page2Index];

                         }

                         completion:^(BOOL completion){

                                 NSLog(@"finished %d",finished);

                         }

CATransition动画转场

对于UIView使用:

CATransition *animation = [CATransition animation];

animation.delegate = self;

animation.duration = 1.0f;

animation.timingFunction = UIViewAnimationCurveEaseInOut;

animation.type = kCATransitonFade;

animation.subtype = kCATransitionFromRight;

[view exchangeSubviewAtIndex:page1Index withSubviewAtIndex:page2Index];

[view.layer addAnimation:animation forKey:@"animation"];

对月ViewController使用

CATransition *ca = [CATransition animation];

[ca setType:@"cube"];

[ca setSubtype:kCATransitionFromRight];

[ca setDuration:1.0f];

[self.navigationController.view.layer addAnimation:ca forKey:@"test"];

[self.navigationController pushViewController:svc animated:YES];

[svc release];

animation.type类型

kCATransitionFade,kCATransitionMoveIn,kCATransitionPush,kCATransitionReveal

animation.subtype类型

kCATransitionFromRight,kCATransitionFromLeft,kCATransitionFromTop,kCATransitionFromButtom

CATransition包含了若干(type)私有函数,分别是

cube,suckEffect,oglFlip,rippleEffect,pageCurl,pageUnCurl,cameralrisHollowOpen,camralrisHollowClose

抱歉!评论已关闭.