2011-05-09 13 views
7

पर मारते समय UIGestureRecognizer को अनदेखा कर रहा है मेरे पास एक इशारा पहचानकर्ता स्थापित है ताकि स्क्रीन टैप होने पर मेरी टूलबार नीचे स्लाइड हो। जब मैंने बार पर एक बटन मारा, तो यह टैप के रूप में गिना जाता है। मैं उन मामलों में इशारा कैसे रद्द करूं?बटन

धन्यवाद

उत्तर

15

आप SimpleGestureRecognizers नमूना परियोजना देख सकते हैं।

http://developer.apple.com/library/ios/#samplecode/SimpleGestureRecognizers/Introduction/Intro.html

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 

    // Disallow recognition of tap gestures in the button. 
    if ((touch.view == button) && (gestureRecognizer == tapRecognizer)) { 
     return NO; 
    } 
    return YES; 
} 
+0

gestureRecognizer.view समग्र दृष्टिकोण, नहीं उपकरण पट्टी/बटन के रूप में सूचीबद्ध किया जा रहा है। – smokingoyster

+0

मैंने उदाहरण अपडेट किया। – jaminguy

+3

यह अगर कथन एक टूलबार में हर बटन को अनदेखा करने के लिए काम करता है। इसे खोजने के लिए मुझे एक मिनट लगा, सोचा कि यह जोड़ने लायक हो सकता है। अगर ([touch.view isDescendantOfView: _toolbar]) – smokingoyster

0

स्विफ्ट में:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { 
    if touch.view is UIButton { 
     return false 
    } 
    return true 
}