IOS动画 (李梦珂)

一、UIView基础动画

1.动画的设置
(1).传统方式设置动画

// 动画开始
[UIView beginAnimations:@"textAnimations" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
//UIViewAnimationCurveEaseInOut开始时和结束时慢  中间快
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
CGRect frame= self.myview.frame;
frame.origin.y += 400;
self.myview.frame = frame;


(2) .用block语法设置动画

[UIView animateWithDuration:0.5 animations:^{

        CGRect frame= self.myview.frame;
        frame.origin.y += 400;
        self.myview.frame = frame;
}];

2.监听事件的结束
(1)block语法监听
self.myview.alpha = 1;
[UIView animateWithDuration:0.5 animations:^{
    CGRect frame= self.myview.frame;
                frame.origin.y += 400;
                self.myview.frame = frame;
    self.myview.alpha = 0;
    //缩放变换
    self.myview.transform =     CGAffineTransformMakeScale(0.01, 0.01);
}completion:^(BOOL finished)
 {
     if(finished)
     {
         [UIView animateWithDuration:0.5 animations:^{

                         CGRect frame= self.myview.frame;
                         frame.origin.y -= 400;
                         self.myview.frame = frame;

             self.myview.alpha = 1;
             self.myview.transform = CGAffineTransformIdentity;
                 }];

     }
 }];

(2)设置代理监听
  //  动画结束时调用  (传统方式监听动画结束)

[UIView setAnimationDidStopSelector:@selector(StopAnnimotion)];
[UIView commitAnimations];

二、视图切换动画

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
CGRect frame= self.myview.frame;
frame.origin.y -= 400;
self.myview.frame = frame;
[UIView commitAnimations];

三、自定义动画

CATransition *animation = [[CATransition alloc]init];
animation.type =  kCATransitionReveal;
animation.subtype = kCATransitionFromTop;
animation.repeatCount = 20;

animation.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] ;
animation.duration = 0.5;

[self.myview.layer addAnimation:animation forKey:@"animationkey"];
[self.myview exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

[self.navigationController.view.layer addAnimation:animation forKey:@"key"];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值