[英]Why cant I rotate my imageview with one finger Swift?
So Im making a DJ app and I have this turntable that I would like to spin to the left and right using touch. 因此,我正在制作一个DJ应用,我有这个转盘,我想使用触摸向左和向右旋转。 I got it to move when a song is being played but not sure how to get it to spin using touch.
当播放歌曲时,我可以移动它,但不确定如何使用触摸使其旋转。
EDIT******* I got it to work but I need to rotate the imageview using one finger instead of two. 编辑*******我可以使用它,但是我需要使用一根手指而不是两只手指旋转imageview。 How would I get that to work?
我将如何工作? Thank you
谢谢
class ViewController: UIViewController, MPMediaPickerControllerDelegate {
var angle: CGFloat = 0
var rotate = UIRotationGestureRecognizer()
override func viewDidLoad() {
super.viewDidLoad()
self.rotate = UIRotationGestureRecognizer(target: self, action: #selector(ViewController.rotate(_:)))
self.leftTurnTable.addGestureRecognizer(self.rotate)
}
func rotate(r:UIRotationGestureRecognizer) {
self.leftTurnTable.transform = CGAffineTransformMakeRotation(angle+r.rotation)
if r.state == UIGestureRecognizerState.Ended {
self.angle += r.rotation
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first
if touch!.view === leftTurnTable {
let position = touch!.locationInView(self.view)
let target = leftTurnTable.center
let angle = atan2(target.y-position.y, target.x-position.x)
leftTurnTable.transform = CGAffineTransformMakeRotation(angle)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.