zoukankan      html  css  js  c++  java
  • ios 如何令一张图片左右晃动

     

       

    //开始动画

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

        momAnimation.fromValue = [NSNumber numberWithFloat:-0.3];

        momAnimation.toValue = [NSNumber numberWithFloat:0.3];

        momAnimation.duration = 0.5;

        momAnimation.repeatCount = CGFLOAT_MAX;

        momAnimation.autoreverses = YES;

        momAnimation.delegate = self;

        [_momImageView.layer addAnimation:momAnimation forKey:@"animateLayer"];

    //暂停动画,图片未复位

    -(void)pauseLayer:(CALayer*)layer

    {

        CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];

        layer.speed = 0.0;

        layer.timeOffset = pausedTime;

    }

    //重新开始动画

    -(void)resumeLayer:(CALayer*)layer{

        CFTimeInterval pausedTime = [layer timeOffset];

        layer.speed = 1.0;

        layer.timeOffset = 0.0;

        layer.beginTime = 0.0;

        CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;

        layer.beginTime = timeSincePause;

    }

    //移除动画,图片复位

    [self.momImageView.layer removeAllAnimations];

  • 相关阅读:
    计算机网络基础知识整理
    计算机操作系统知识整理
    各类编程语言的主要用途
    计算机的基本组成知识整理
    对IT行业的看法和对软件工程的理解
    正规文法转换
    语法树评论
    c语言文法定义
    词法分析
    0909我对编译原理的见解
  • 原文地址:https://www.cnblogs.com/allanliu/p/4213506.html
Copyright © 2011-2022 走看看