UIView.Animation不起作用,因为只有转换层

时间:2017-05-21 12:10:52

标签: swift core-animation

我正在尝试启动动画,但收到了error消息。

  

“ - 在仅变换图层中更改属性contentsGravity,将无效”

有人知道吗?

import UIKit

class Loading: UIView{

let leftEye = UIImageView()
let rightEye = UIImageView()


//50, 50 px
override init(frame: CGRect) {
    super.init(frame: frame)

    leftEye.frame = CGRect(x: 5.5, y: 16.5, width: 17, height: 17)
    leftEye.layoutIfNeeded()
    leftEye.layer.cornerRadius = leftEye.frame.size.width/2
    leftEye.clipsToBounds = true
    leftEye.image = UIImage(named: "leftEye")
    leftEye.center = CGPoint(x: 14, y: 25)

    rightEye.frame = CGRect(x: 27.5, y: 16.5, width: 17, height: 17)
    rightEye.layoutIfNeeded()
    rightEye.layer.cornerRadius = leftEye.frame.size.width/2
    rightEye.clipsToBounds = true
    rightEye.image = UIImage(named: "rightEye")
    rightEye.center = CGPoint(x: 36, y: 25)

    super.addSubview(leftEye)
    super.addSubview(rightEye)

    super.backgroundColor = .black    
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

func loading(start: Bool){

    UIView.animate(withDuration: .infinity, delay: 0, options: [], animations: { [unowned self] in
        self.leftEye.transform = CGAffineTransform(rotationAngle: CGFloat.pi)

        self.rightEye.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
    })
  }   
}

0 个答案:

没有答案