Pan手勢識別的聲明:
let panRecognizer = ?UIPanGestureRecognizer(target: self, action: #selector(URVIEWController.respondsToPenGesture))
self.view.addGestureRecognizer(panRecognizer)
設(shè)置后面調(diào)用的方法:respondsToPenGesture
func respondsToPenGesture(sender: UIPanGestureRecognizer) {}
最重要的就是在方法中根據(jù) 手勢的state來作出不同的響應(yīng):
if (sender.state == UIGestureRecognizerState.Began) {
startPanLocation = sender.locationInView(URVIEW)
} else if (sender.state == UIGestureRecognizerState.Changed) {
let stopLocation = sender.locationInView(URVIEW)
let abscissaChange = stopLocation.x - startPanLocation!.x
} else if (sender.state == UIGestureRecognizerState.Ended) {
let stopLocation = sender.locationInView(URVIEW)
let abscissaChange = stopLocation.x - startPanLocation!.x
}
需要注意的是 startPanLocation 你需要存在一個全局變量里暂刘,因為在你state.changed時候,如果不是全劇變量你取不到starPanLocation的值。
剩下的事情就比較簡單了 你獲得了abscissaChange 同理也能簡單的到豎直方向的變化值粱锐,用這個值來對于你想要改變的值做一個加減計算就可以輕松實現(xiàn) Slider的功能。
Prisma的slider的功能也應(yīng)該是一個道理來實現(xiàn)的返奉,在view上在設(shè)置一個UITextlabel 就能達(dá)到一摸一樣的功效哄尔,(當(dāng)然還要加上一個延遲消失的效果,可以用dispatch_after來實現(xiàn))
Good Luck 捷犹,tlm .?