你好我有一个快速的应用程序,我每次触摸都开始调用一个函数,但我不希望在用户滑动时调用touchesBegan。我怎么能避免这个?
触动开始了:
/((?:[^=,]+)=(?:[^=]+)),/g
滑动:
{{1}}
此外,我不想做任何接触结束,因为这会增加我不能拥有的延迟
答案 0 :(得分:0)
让你的UIViewController查看一个自定义类并处理这些触摸 - 它们应该以你尝试的方式接收,但只能在UIView类本身中接收。
答案 1 :(得分:0)
如果要将滑动与触摸分开,可以使用delaysTouchesBegan方法轻松完成,例如:
let swipeRight:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedRight:"))
swipeRight.direction = .Right
swipeRight.cancelsTouchesInView = true
swipeRight.delaysTouchesBegan = true
view.addGestureRecognizer(swipeRight)
let swipeLeft:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedLeft:"))
swipeLeft.direction = .Left
swipeLeft.cancelsTouchesInView = true
swipeLeft.delaysTouchesBegan = true
view.addGestureRecognizer(swipeLeft)
let swipeUp:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedUp:"))
swipeUp.direction = .Up
swipeUp.cancelsTouchesInView = true
swipeUp.delaysTouchesBegan = true
view.addGestureRecognizer(swipeUp)
let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedDown:"))
swipeDown.direction = .Down
swipeDown.cancelsTouchesInView = true
swipeDown.delaysTouchesBegan = true
view.addGestureRecognizer(swipeDown)
在viewDidLoad或didMoveToView中(如果你在spritekit场景中)
分别制作方法:
func swipedRight(sender:UISwipeGestureRecognizer){
print("swiped right")
}
func swipedLeft(sender:UISwipeGestureRecognizer){
print("swiped left")
}
func swipedUp(sender:UISwipeGestureRecognizer){
print("swiped up")
}
func swipedDown(sender:UISwipeGestureRecognizer){
print("swiped down")
}
然后,您可以使用官方委托方法控制您的触摸,例如:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
...// handle your touches..
}