我想在UIViewController中追踪我手指的位置。我使用以下函数实现了这个功能,这非常有效!
override func viewDidLoad() {
view.userInteractionEnabled = true
view.multipleTouchEnabled = true
super.viewDidLoad()
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
//Create subview and place it under your finger.
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
//Here methods which tracks the moves of the finger and updates the subviews position.
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
//Remove subview from superview overhere.
}
我有两个问题:
我应该以另一种方式实现吗?我也尝试使用UIGestureRecognizer,但没有成功。
我添加了这个功能
override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?) {
}
当我点击屏幕上的第6个手指时,会调用此方法。