2016-07-08 136 views
1

我有這樣的功能:斯威夫特復位transitionInView

func moveAxes(recognizer: UIPanGestureRecognizer) { 
    switch recognizer.state { 
    case .Changed: 
     var changePoint = recognizer.translationInView(self) 
     axesCenter = CGPoint(x: axesCenter.x + changePoint.x, y: axesCenter.y + changePoint.y) 

     print("x: \(changePoint.x) y: \(changePoint.y)") 
     changePoint.x = 0.0 
     changePoint.y = 0.0 
    default: 
     break 
    } 
} 

應該在我的UIView軸移動。問題是,

changePoint.x = 0.0 
changePoint.y = 0.0 

不重置覆蓋的距離,它保持加起來,所以我的軸開始加速遠離移動點。如何重置覆蓋距離以避免此問題?

p.s. axesCenter被初始化爲x: frame.midXy: frame.midY

回答

0

我已經通過切換這個解決我的問題:這個 recognizer.setTranslation(CGPoint(x: 0.0, y: 0.0), inView: self)

changePoint.x = 0.0 
changePoint.y = 0.0