/ / स्विफ्ट फायरिंग स्पर्श नहीं है अगर स्वाइप - स्विफ्ट, touchesbegan

स्विफ्ट फायरिंग स्पर्श नहीं है अगर स्वाइप - स्विफ्ट, touchesbegan

हैलो मेरे पास एक तेज़ एप्लिकेशन है जहां मैंने स्पर्श किया है हर बार एक समारोह को कॉल करना शुरू किया है, लेकिन मुझे स्पर्श नहीं करना चाहिए अगर उपयोगकर्ता इसके बजाय स्वाइप कर रहा है तो उसे बुलाया जाए। मैं इससे कैसे बच सकता हूं?

टच शुरू हुआ:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
//function call
}

स्वाइप करना:

var Swipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
Swipe.direction = .Up
//Swipe.cancelsTouchesInView = true        did not make a difference
view.addGestureRecognizer(Swipe)

इसके अलावा मैं छूना नहीं चाहता क्योंकि अंत में देरी हो सकती है जो मेरे पास नहीं हो सकती है

उत्तर:

जवाब के लिए 0 № 1

अपने UIViewController को एक कस्टम क्लास देखें और वहां इन स्पर्शों को संभालें - उन्हें जिस तरीके से आपने कोशिश की है उसे प्राप्त किया जाना चाहिए, लेकिन केवल यूआईवीव क्लास में ही।


जवाब के लिए 0 № 2

यदि आप स्वाइप को छूने से अलग करना चाहते हैं तो आप आसानी से देरी के साथ आसानी से कर सकते हैं, उदाहरण के लिए:

        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)

आपके विचार में डिडलोड या didMoveToView (यदि आप एक स्प्राइटकिट दृश्य में हैं)

और क्रमशः विधियों को बनाओ:

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..
}