animate rotation UIImageView in swift

后端 未结 10 2275
抹茶落季
抹茶落季 2021-02-06 23:11

I\'m trying to animate a rotation of 180 degrees of a UIImageView in Swift

    UIView.animateWithDuration(1.0, animations: { () -> Void in
              


        
10条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-06 23:16

    90 degrees rotation

    var shouldRotateArrow = false {
        didSet {
            rotateArrow()
        }
    }
    
    private func rotateArrow() {
        let angle: CGFloat = shouldRotateArrow ? .pi / 2 : 0
        UIView.animate(withDuration: Constants.arrowRotationDuration) {
            self.arrowImageView.transform = CGAffineTransform(rotationAngle: angle)
        }
    }
    

提交回复
热议问题