原文地址:http://www.raywenderlich.com/76147/uikit-dynamics-tutorial-swift
在原文的最下面有这样一段代码,实现的大概效果是:当手指触摸屏幕某一点时,view就移动到那一点,我不是很清楚其中这段if语句,if语句的意思应该是把snap行为移除,可是这有什么作用,为什么把if语句删掉了就不能达到上面的效果
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
if (snap != nil) {
animator.removeBehavior(snap)
}
let touch = touches.first! as UITouch
snap = UISnapBehavior(item: square, snapToPoint: touch.locationInView(view))
animator.addBehavior(snap)
}
怪我咯2017-04-17 17:29:12
That is used to block touch points that have not been completed or there is no reset after the event is completed, in response to your last click event.