32. demo
func pan(gesture:UIPanGestureRecognizer) {
switch gesture.state {
case .Changed:
fallthrough
case .Ended:
let translation = gesture.translationInView(blueView)
println("translation (translation)")
gesture.setTranslation(CGPointZero, inView:blueView)
default:
break
}
}
觀察呼叫gesture.setTranslation和沒有呼叫gesture.setTranslation的差別
33. 利?用pan移動view:?方法1
func pan(gesture:UIPanGestureRecognizer) {
switch gesture.state {
case .Began:
originalCenter = blueView.center
case .Changed:
fallthrough
case .Ended:
let translation = gesture.translationInView(blueView)
blueView.center = CGPointMake(originalCenter.x +
translation.x,
originalCenter.y + translation.y);
default:
break
}
}
class ViewController: UIViewController {
var originalCenter:CGPoint!
34. 利?用pan移動view:?方法2
func pan(gesture:UIPanGestureRecognizer) {
switch gesture.state {
case .Changed:
fallthrough
case .Ended:
let translation = gesture.translationInView(blueView)
let originalCenter = blueView.center
blueView.center = CGPointMake(originalCenter.x +
translation.x,
originalCenter.y + translation.y);
gesture.setTranslation(CGPointZero, inView:blueView)
default:
break
}
}
35. pan gesture
var minimumNumberOfTouches: Int // default is 1. the minimum
number of touches required to match
var maximumNumberOfTouches: Int // default is UINT_MAX. the
maximum number of touches that can be down
48. Once the MVC is prepared, it should run on its own power
(only using delegation to talk back)
It is crucial to understand that this preparation is happening
BEFORE outlets get set!!