ios 对于UIView的动画的初步理解

基本函数:
+ (void)beginAnimations:(NSString *)animationID context:(void *)context; // 开始准备动画
+ (void)commitAnimations; // 运行动画
// 没有get方法,下面的set在外调用无效
+ (void)setAnimationDelegate:(id)delegate; // 委托default = nil
+ (void)setAnimationWillStartSelector:(SEL)selector; // default = NULL. -animationWillStart:(NSString *)animationID context:(void *)context
+ (void)setAnimationDidStopSelector:(SEL)selector; // default = NULL. -animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
+ (void)setAnimationDuration:(NSTimeInterval)duration; // default = 0.2动画时间
+ (void)setAnimationDelay:(NSTimeInterval)delay; // default = 0.0延迟多少时间开始执行动画
+ (void)setAnimationStartDate:(NSDate *)startDate; // default = now ([NSDate date])动画开始日期?不知道啥用.- -
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve; // default = UIViewAnimationCurveEaseInOut动画方式
+ (void)setAnimationRepeatCount:(float)repeatCount; // default = 0.0. May be fractional重复次数
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses; // default = NO. YES的话,动画(非最后一次)结束后动态复原到最开始状态
+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState; // default = NO. YES,停止之前的动画,从现在这里开始新动画the current view position is always used for new animations -- allowing animations to "pile up" on each other. Otherwise, the last end state is used for the animation (the default).

+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache; // 添加动画到view上,cache是YES的时候比较高效,但是动画过程中不能更新界面上的内容,NO时每一帧都重新画,可以实时更新
+ (void)setAnimationsEnabled:(BOOL)enabled; // 是否忽略一些动画设置
+ (BOOL)areAnimationsEnabled;
复制代码

动画示例:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:2.7];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
// operation>>>
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
// end<<<<<<
[UIView commitAnimations];


Transition的取值范围:
typedef enum {
UIViewAnimationTransitionNone,//不使用动画
UIViewAnimationTransitionFlipFromLeft,//从左向右旋转翻页
UIViewAnimationTransitionFlipFromRight,//从右向左旋转翻页,与UIViewAnimationTransitionFlipFromLeft相反
   
   
 
UIViewAnimationTransitionCurlUp,//卷曲翻页,从下往上 UIViewAnimationTransitionCurlDown,卷曲翻页,从上往下 } UIViewAnimationTransition; 示例:
[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]; //提交动画 CATransiton

CATransiton官方提供4种动画效果,分别为:

NSString * const kCATransitionFade;//渐渐消失

NSString * const kCATransitionMoveIn;//覆盖进入

NSString * const kCATransitionPush;//推出

NSString * const kCATransitionReveal;//与MoveIn相反

例子:

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值