Dobrý deň, mám rýchlu aplikáciu, kde mám dotyky začal volať funkciu zakaždým, ale ja nechcem, aby dotykyBegan dostal, keď používateľ namieril. Ako sa tomu možno vyhnúť?
Začali sa dotýkať:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
//function call
}
Swipe:
var Swipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
Swipe.direction = .Up
//Swipe.cancelsTouchesInView = true did not make a difference
view.addGestureRecognizer(Swipe)
Tiež nechcem robiť dotyky ukončené, pretože to zvyšuje oneskorenie, ktoré nemôžem mať
odpovede:
0 pre odpoveď č. 1Uvidíte vlastnú triedu UIViewController a manipulujte s týmito dotykmi - mali by byť prijaté tak, ako ste to skúšali, ale iba v triede UIView.
0 pre odpoveď č. 2
Ak chcete oddeliť prsty od dotykov, môžete to urobiť jednoducho metódou oneskoreniaTouchesBegan, napríklad:
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)
podľa vášho názoruDidLoad alebo didMoveToView (ak sa nachádzate v scéne spritekit)
A vykonajte príslušné metódy:
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")
}
Potom môžete ovládať svoje dotyky pomocou oficiálnych delegátov, ako sú:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
...// handle your touches..
}