सफलतापूर्वक संयोजित करने के लिए दोनों की जरूरत है:
1º हैडर पर इशारा प्रतिनिधि इंटरफेस में जोड़े
@interface ViewController : ViewController <UIGestureRecognizerDelegate>
2º इशारा घटनाओं बनाएँ और स्रोत फ़ाइल में एक दृश्य में जोड़ने के लिए:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touch:)];
[tap setNumberOfTapsRequired:1]; // Set your own number here
[tap setDelegate:self]; // Add the <UIGestureRecognizerDelegate> protocol
UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouch:)];
[longTap setNumberOfTapsRequired:0]; // Set your own number here
[longTap setMinimumPressDuration:1.0];
[longTap setDelegate:self]; // Add the <UIGestureRecognizerDelegate> protocol
[tap requireGestureRecognizerToFail:longTap]; // Priority long
[self.view addGestureRecognizer:tap];
[self.view addGestureRecognizer:longTap];
3º स्रोत फ़ाइल में कॉलबैक जोड़ें:
- (void) touch: (UITapGestureRecognizer *)recognizer
{
CGPoint location = [recognizer locationInView: self.HUDview];
if (recognizer.state == UIGestureRecognizerStateBegan)
{
NSLog(@"touch UIGestureRecognizerStateBegan");
}
if (recognizer.state == UIGestureRecognizerStateEnded)
{
NSLog(@"touch UIGestureRecognizerStateEnded");
//NSLog(@"Position of touch: %.3f, %.3f", location.x, location.y); // Position landscape
}
}
- (void) longTouch: (UILongPressGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateBegan)
{
NSLog(@"longTouch UIGestureRecognizerStateBegan");
}
if (recognizer.state == UIGestureRecognizerStateEnded)
{
NSLog(@"longTouch UIGestureRecognizerStateEnded");
}
}
4º सेट इशारा पहचानकर्ता उपलब्ध:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
सलाम बंद। अच्छा उत्तर। –
भी टोपी बंद करो। कोड की यह आखिरी पंक्ति है जो मुझे चाहिए। – dellos