美文网首页
iOS CABasicAnimation基本动画

iOS CABasicAnimation基本动画

作者: 雪影无痕 | 来源:发表于2021-08-29 16:32 被阅读0次

- (void)viewDidLoad {

    [super viewDidLoad];

    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 150, 150, 150)];

    _imageView.image= [UIImageimageNamed:@"0.JPG"];

    [self.viewaddSubview:_imageView];

}

-(void)touchesBegan:(NSSet *)toucheswithEvent:(UIEvent*)event{

    //取得动画

    CABasicAnimation *animation = (CABasicAnimation*)[_imageView.layer  animationForKey:@"animation1"];

    if(animation ==nil) {

        [self rotationAction];

    }else{

        if(_imageView.layer.speed==0) {

            [selfstartAnimation];

        }else{

        [self pauseAnimation];

        }

    }

}

//暂停动画c

-(void)pauseAnimation{

    //0---3  1.5  取得当前动画停止的时间

  CFTimeInterval  pauseTime =  [_imageView.layer  convertTime:CACurrentMediaTime() fromLayer:nil];

    _imageView.layer.timeOffset= pauseTime;

    _imageView.layer.speed=0;

}

//开始动画

-(void)startAnimation{

    CFTimeInterval  time =CACurrentMediaTime() -  _imageView.layer.timeOffset;

    _imageView.layer.beginTime= time;

    _imageView.layer.speed=1;

    _imageView.layer.timeOffset = 0;

}

- (void)rotationAction{

     CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    basicAnimation.fromValue=0;

    basicAnimation.toValue=@ (M_PI*2);

    basicAnimation.duration=3;

    basicAnimation.repeatCount=HUGE_VALF;  //一直重复

    [_imageView.layer  addAnimation:basicAnimationforKey:@"animation1"];

}

//缩放动画

-(void)scaleAnimation{

        CABasicAnimation*basicAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.scale"];

    basicAnimation.fromValue=@0;

    basicAnimation.toValue=@2;

    basicAnimation.duration=0.5;

    //下面两步保持动画结束后的状态不变

    //    basicAnimation.removedOnCompletion = NO;

    //    basicAnimation.fillMode = kCAFillModeForwards;

    //在恢复之前状态过程自动添加动画

    basicAnimation.autoreverses=YES;

    //添加动画

    [_imageView.layeraddAnimation:basicAnimationforKey:nil];

}

相关文章

  • 2018-11-28

    1、CABasicAnimation基本动画 各种属性 CABasicAnimation基本动画 各种属性 - u...

  • iOS 动画

    CABasicAnimation 和 CASpringAnimation CABasicAnimation基本动画...

  • iOS知识点总结(6)- 动画

    CABasicAnimation——基本动画 简单的动画效果: CABasicAnimation *moveAni...

  • iOS CABasicAnimation基本动画

    - (void)viewDidLoad { [super viewDidLoad]; _imageView...

  • iOS动画的几种实现方式:

    一、CABasicAnimation基本动画(fromValue和toValue) 二、CAKeyframeAni...

  • iOS-核心动画

    基本动画CABasicAnimation,确定keyPath,animation的duration、fromVal...

  • iOS 动画CABasicAnimation

    前言 文从CABasicAnimation,UIBezierPath,CAShapeLayer三个方面完整的阐述i...

  • iOS动画详解

    iOS动画 引用简书上一篇关于iOS动画的文章,介绍的很详细。仅供参考! 关于CABasicAnimation的文...

  • 核心动画(二)

    一、CABasicAnimation——基本动画 CAPropertyAnimation的子类 属性说明:from...

  • iOS 核心动画

    //基本动画 实现平移动/旋转/等CABasicAnimation * anima=[CABasicAnimati...

网友评论

      本文标题:iOS CABasicAnimation基本动画

      本文链接:https://www.haomeiwen.com/subject/srxgiltx.html