पर दो बार टैप करें मेरे पास एक बटन है और मैं उस पर नल का परीक्षण कर रहा हूं, एक टैप के साथ यह एक पृष्ठभूमि रंग बदलता है, जिसमें दो नल रंग होते हैं और तीन टैप एक और रंग फिर से होते हैं। कोड है:आईओएस - यूबूटन
- (IBAction) button {
UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnce:)];
UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTwice:)];
UITapGestureRecognizer *tapTrice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTrice:)];
tapOnce.numberOfTapsRequired = 1;
tapTwice.numberOfTapsRequired = 2;
tapTrice.numberOfTapsRequired = 3;
//stops tapOnce from overriding tapTwice
[tapOnce requireGestureRecognizerToFail:tapTwice];
[tapTwice requireGestureRecognizerToFail:tapTrice];
//then need to add the gesture recogniser to a view - this will be the view that recognises the gesture
[self.view addGestureRecognizer:tapOnce];
[self.view addGestureRecognizer:tapTwice];
[self.view addGestureRecognizer:tapTrice];
}
- (void)tapOnce:(UIGestureRecognizer *)gesture
{ self.view.backgroundColor = [UIColor redColor]; }
- (void)tapTwice:(UIGestureRecognizer *)gesture
{self.view.backgroundColor = [UIColor blackColor];}
- (void)tapTrice:(UIGestureRecognizer *)gesture
{self.view.backgroundColor = [UIColor yellowColor]; }
समस्या यह है कि पहले नल काम करता है नहीं है, अन्य हाँ। यदि मैं बटन के बिना इस कोड का उपयोग करता हूं तो यह पूरी तरह से काम करता है। धन्यवाद।
क्या आप बटन टैप पर यह इशारा जोड़ रहे हैं? आप इसेडिडलोड में क्यों नहीं जोड़ते? – iDev
क्योंकि मुझे केवल इस दृश्य का एक छोटा सा हिस्सा उपयोग करना चाहिए। – Kerberos
लेकिन आपका कोड पूरे 'self.view' पर इशारा सेट कर रहा है। आपको इसके जवाब में दिखाए गए अनुसार इसे बदलना चाहिए। – iDev