У меня есть изображение, которое я хочу поворачивать каждый раз, когда пользователь проводит по нему пальцем.Это работает в первый раз, и только в первый раз!Как получается, что представление теряет распознаватель жестов смахивания?
myCircle = UIImageView( ... )
myCircle.isUserInteractionEnabled = true
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(swiping(sender:)))
swipeLeft.direction = .left
myCircle.addGestureRecognizer(swipeLeft)
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(swiping(sender:)))
swipeRight.direction = .right
myCircle.addGestureRecognizer(swipeRight)
}
@objc func swiping(sender: UISwipeGestureRecognizer) {
// this function only called the first time!
if sender.direction == UISwipeGestureRecognizer.Direction.left {
myCircleRotation -= CGFloat(Double.pi/2)
} else if sender.direction == UISwipeGestureRecognizer.Direction.right {
myCircleRotation += CGFloat(Double.pi/2)
}
// if I comment out this next line, function is called (correctly) every swipe!
myCircle.transform = CGAffineTransform(rotationAngle: myCircleRotation)
}