CoreAnimation 核心动画 简称CA

-、动画块

fram bounds center alpha
Transition 过渡
transform

我们之前使用过的UIView动画 其实本质上也是 CoreAnimation实现的 只是对他里面的动画进行了封装

视图(UIView)支持动画的属性 fram bounds center alpha transform 以及动画延迟 动画曲线(淡出淡入 动画过渡)重复次数 反转

视图(UIView)支持动画的属性有 frame bounds center alpha transform 以及动画延迟 动画曲线( 淡入淡出 动画过渡) 重复次数

  • (void)setAnimationDelegate:(id)delegate;
  • (void)setAnimationWillStartSelector:(SEL)selector 当动画即将开始时,执行delegate对象的selector,并且把beginAnimations:context:中传入的参数传进selector
  • (void)setAnimationDidStopSelector:(SEL)selector 当动画结束时,执行delegate对象的selector,并且把beginAnimations:context:中传入的参数传进selector

  • (void)setAnimationDuration:(NSTimeInterval)duration 动画的持续时间,秒为单位

  • (void)setAnimationDelay:(NSTimeInterval)delay 动画延迟delay秒后再开始

  • (void)setAnimationStartDate:(NSDate *)startDate 动画的开始时间,默认为now

  • (void)setAnimationCurve:(UIViewAnimationCurve)curve 动画的节奏控制

  • (void)setAnimationRepeatCount:(float)repeatCount 动画的重复次数

  • (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses 如果设置为YES,代表动画每次重复执行的效果会跟上一次相反

  • (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache 设置视图view的过渡效果, transition指定过渡类型, cache设置YES代表使用视图缓存,性能较好

初始化一个UIImageView

imageView = [[UIImageView alloc]initWithFrame:self.view.frame];
    imageView.image = [UIImage imageNamed:@"登陆.jpg"];
    [self.view addSubview:imageView];

初始化一个UIbutton 调用动画的方法


    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 100, 40);
    button.center = self.view.center;
    button.backgroundColor = [UIColor brownColor];
    [button addTarget:self action:@selector(viewAnimation3) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

pragma mark ———-fram bounds center alpha—-

1、

-(void)viewAnimation1
{
//    以前我们是直接这样做
//    [UIView animateWithDuration:3 animations:^{
//       
//        imageView.alpha = 0.5;
//        
//    }];



//    开始动画
    [UIView beginAnimations:@"animation" context:nil];

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

//    动画效果
    imageView.alpha = 0.5;
    imageView.bounds = CGRectMake(0, 0, 100, 100);

//    提交动画 回去执行动画
  //不提交动画 就不会执行动画
    [UIView commitAnimations];
}
#pragma mark------Transition
-(void)viewAnimation2
{
    /*
     typedef NS_ENUM(NSInteger, UIViewAnimationTransition) {
     UIViewAnimationTransitionNone,
     UIViewAnimationTransitionFlipFromLeft, 从左面翻转
     UIViewAnimationTransitionFlipFromRight,从右面翻转
     UIViewAnimationTransitionCurlUp, 向上翻页
     UIViewAnimationTransitionCurlDown,向下翻页
     };
     */

//    写一个动画 必须有一个 开始动画 和提交动画

//    开始动画
    [UIView beginAnimations:@"animation" context:nil];

//    持续时间
    [UIView setAnimationDuration:5];

//    设置 UIView 的过渡动画
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:imageView cache:YES];

//    设置动画效果 过渡的状态
   /*
    typedef NS_ENUM(NSInteger, UIViewAnimationCurve) {
    UIViewAnimationCurveEaseInOut,         // slow at beginning and end  慢进慢出
    UIViewAnimationCurveEaseIn,            // slow at beginning  快进
    UIViewAnimationCurveEaseOut,           // slow at end  快出
    UIViewAnimationCurveLinear   匀速
    };

    */

    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

//    设置UIView的代理(如果想 监测 动画的状态 是否结束了 就必须挂上代理)
    [UIView setAnimationDelegate:self];
//    当动画结束的时候:
    [UIView setAnimationDidStopSelector:@selector(finishiAnimation)];

//    提交动画
    [UIView commitAnimations];

}
-(void)finishiAnimation
{


    //    开始动画
    [UIView beginAnimations:@"animation" context:nil];

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

    //    动画效果
    imageView.alpha = 0.5;
    imageView.bounds = CGRectMake(0, 0, 0, 0);

    //    提交动画 回去执行动画

    [UIView commitAnimations];


}

3、

-(void)viewAnimation3
{

    //    开始动画
    [UIView beginAnimations:@"animation" context:nil];

    //    设置动画的持续时间
    [UIView setAnimationDuration:3];
//    transform 如果没有还原transform 它会保持 改变后的模样(会在变化之后的大小的基础上继续缩小)
//    imageView.transform = CGAffineTransformScale(imageView.transform, 0.5, 0.5);

//    imageView.transform=CGAffineTransformRotate(imageView.transform, M_PI_4); //实现的是旋转



    imageView.transform=CGAffineTransformTranslate(imageView.transform, 100, 0); //实现的是平移


    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(restore)];

    //    提交动画 回去执行动画

    [UIView commitAnimations];
}
-(void)restore
{
//    CGAffineTransformIdentity还原视图 的 初始状态
    [UIView animateWithDuration:2 animations:^{

         imageView.transform =CGAffineTransformIdentity;
    }];



}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ldl_csdn_ios

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值