我有一个标签和UIImage布局如下。
LabelMonth ImgArrowDown
此LabelMonth的TapGestureRecognizer如下所示。
当用户点击LabelMonth时,ImageArrowDown将旋转360,使其看起来向上。
问题:
viewDidLoad中(){
let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:
#selector(HandleImgRotation))
LabelMonth.isUserInteractionEnabled = true LabelMonth.addGestureRecognizer(tapGestureRecognizer)
}
func HandleImgRotation(_sender:AnyObject){
UIView.animate(withDuration:1.0, animations: ({self.imgArrowDown.transform = CGAffineTransform(rotationAngle: self.radian(degree:360))
}))
}
func radian(degrees:Double) -> CGFloat{
return CGFloat(degrees * .pi/degrees)
}
由于
答案 0 :(得分:1)
以下方法应解决您的问题...
var rotated = false
func HandleImgRotation() {
UIView.animate(withDuration: 2.0) {
if !self.rotated {
UIView.animate(withDuration:1.0, animations: ({
ImgArrowDown.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI * 0.999) )
self.rotated = true
}))
} else {
UIView.animate(withDuration:1.0, animations: ({
ImgArrowDown.transform = CGAffineTransform.identity
self.rotated = false
}))
}
}
}