iOS实现音乐播放器图片旋转示例

  介绍

今天就跟大家聊聊有关iOS实现音乐播放器图片旋转示例,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

通过给继承与UIImageView的类CXGImageView添加CABasicAnimation转动动画,实现播放器图片转动效果。

主要提供三个方法:startRotating, stopRotating, resumeRotate startRotating

///开始动画
  func startRotating () {
  让rotateAnimation=CABasicAnimation (keyPath:“transform.rotation")
  rotateAnimation。isRemovedOnCompletion=false//避免点回家的击键返回,动画停止
  rotateAnimation.fromValue=https://www.yisu.com/zixun/0.0
  rotateAnimation。toValue=双。π* 2
  rotateAnimation。时间=20
  rotateAnimation。repeatCount=MAXFLOAT
  self.layer。添加(rotateAnimation forKey: nil)
  isRotating=true
  }

stopRotating

///停止动画
  func stopRotating () {
  如果isRotating {!
  返回
  }
  让pausedTime=self.layer.convertTime (CACurrentMediaTime (): nil)//让CALayer的时间停止走动
  self.layer。速度=0//让CALayer的时间停留在pausedTime这个时刻
  self.layer。timeOffset=pausedTime
  isRotating=false
  }

resumeRotate

///继续动画
  func resumeRotate () {
  
  如果isRotating {
  返回
  }
  
  如果self.layer。timeOffset==0 {
  startRotating ()
  返回
  }
  
  让pausedTime=self.layer.timeOffset//1。让CALayer的时间继续行走
  self.layer。速度=1.0//2。取消上次记录的停留时刻
  self.layer。timeOffset=0.01//3。取消上次设置的时间
  self.layer。beginTime=0.0//4。计算暂停的时间(这里也可以用CACurrentMediaTime () -pausedTime)
  让timeWhenpause=self.layer.convertTime (CACurrentMediaTime (): nil)——pausedTime//5。设置相对于父坐标系的开始时间(往后退timeSincePause)
  self.layer。beginTime=timeWhenpause
  isRotating=true
  
  }

注意:使用中发现,当点下回家键再次返回应用时,图片停止转动,需要将动画isRemovedOnCompletion置成假的。

看完上述内容,你们对iOS实现音乐播放器图片旋转示例有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。

iOS实现音乐播放器图片旋转示例