旋转图像仅适用于第一个响应[重复]

问题描述 投票:1回答:1

这个问题在这里已有答案:

当我点击我的应用程序中的按钮时,我希望它旋转180度。我的下面的代码有效,但如果它再次点击按钮它根本不旋转,它只是停留在原来的位置。

这是我的代码如下

func animateRecommendButton() {
    UIView.animate(withDuration: 0.25) { () -> Void in
        self.recommendButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
    }
}
ios swift
1个回答
1
投票

而不是更新创建新变换更新按钮的变换

UIView.animate(withDuration: 2.0, animations: {
   sender.transform = sender.transform.rotated(by:CGFloat.pi)
})

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.