Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 旋转图像仅对第一个响应有效_Ios_Swift - Fatal编程技术网

Ios 旋转图像仅对第一个响应有效

Ios 旋转图像仅对第一个响应有效,ios,swift,Ios,Swift,当我点击应用程序中的按钮时,我希望它旋转180度。我下面的代码可以工作,但是如果它再次点击按钮,它根本不会旋转,它只会停留在原来的位置 下面是我的代码 func animateRecommendButton() { UIView.animate(withDuration: 0.25) { () -> Void in self.recommendButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi

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

下面是我的代码

func animateRecommendButton() {
    UIView.animate(withDuration: 0.25) { () -> Void in
        self.recommendButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
    }
}

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

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

答案更有助于解释问题和解决方案,而不是仅“尝试此”代码转储。仅在第一次单击按钮后才显示动画。第一次点击后,它就没有动画了。我收到了,谢谢你给我看这个复制品@rmaddy