Расширение для UIView - постоянное вращение

swift

#1
extension UIView {
    func rotate360Degrees(duration: CFTimeInterval = 1.0) {
        let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
        rotateAnimation.fromValue = 0.0
        rotateAnimation.toValue = CGFloat(M_PI)*2
        rotateAnimation.duration = duration
        rotateAnimation.repeatCount = .infinity
        self.layer.addAnimation(rotateAnimation, forKey: nil)
    }
}

используем

  let testview = UIView(frame: CGRect(x: CGRectGetMidX(self.view.frame)-50, y: CGRectGetMidY(self.view.frame)-50, width: 100, height: 100))
      testview.backgroundColor = UIColor.redColor()
  self.view.addSubview(testview)
    
    //testview.rotate360Degrees() //по умолчанию 1 сек
    testview.rotate360Degrees(2)  //2 сек