`
咖啡动力
  • 浏览: 435002 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

UIView 动画

阅读更多
[size=large][/size]需要在frameworks中添加QuartzCore.framework

在接口程序中加上头文件   #import <QuartzCore/QuartzCore.h>
方法一:CATransition

创建transition
    CATransition *transition = [CATransition animation];
    transition.duration = 1.0f;         /* 间隔时间*/
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; /* 动画的开始与结束的快慢*/
    transition.type = @"rippleEffect"; /* 各种动画效果*/
//@"cube" @"moveIn" @"reveal" @"fade"(default) @"pageCurl" @"pageUnCurl" @"suckEffect" @"rippleEffect" @"oglFlip"

    transition.subtype = kCATransitionFromRight;   /* 动画方向*/
    transition.delegate = self;

    [navigationController.view.layer /* 在想添加CA动画的VIEW的层上添加此代码*/addAnimation:transition forKey:nil];
//另外加一句,transition在申请时用的是+方法,所以不需要自己进行release ,在层上添加后不要认为retainCount已经+1,就还要release

//降效果作用到view的层上面
//实际上CATransition类中还有一个属性是removedOnCompletion,是此动画执行完后会自动remove,默认值为true

//降效果作用到view的层上面
[self.view.layer addAnimation:transition forKey:@"animation"];

方法二:UIView Animation
//开始一个动画块
[UIView beginAnimations:@"animationID" context:nil];
//设置动画块中的动画持续时间(用秒)
[UIView setAnimationDuration:0.5f];
//设置动画块中的动画属性变化的曲线
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//变化曲线还有
(    UIViewAnimationCurveEaseInOut,         // slow at beginning and end
    UIViewAnimationCurveEaseIn,            // slow at beginning
    UIViewAnimationCurveEaseOut,           // slow at end
    UIViewAnimationCurveLinear)

//设置动画块中的动画效果是否自动重复播放。
[UIView setAnimationRepeatAutoreverses:NO];

//设置动画在动画模块中的重复次数
//setAnimationRepeatCount:
//设置动画消息的代理。
[UIView setAnimationDelegate:self];
[UIView
//设置消息给动画代理当动画开始的时候
setAnimationWillStartSelector:@selector(resizeAnimationWillStart:context:)];
[UIView
//设置消息给动画代理当动画停止的时候
setAnimationDidStopSelector:@selector(resizeAnimationDidStop:finished:context:)];


//将效果作用在指定的view
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];

效果还有(UIViewAnimationTransitionFlipFromLeft,UIViewAnimationTransitionFlipFromRight,UIViewAnimationTransitionCurlUp,UIViewAnimationTransitionCurlDown)

//显示在最前面
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
//结束动画
[UIView commitAnimations];


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics