@interface MyCustomView() @end
@implementation MyCustomView
- (instancetype)init {
self = [[[MyClass bundle] loadNibNamed:kOverlayNib owner:self options:nil] firstObject];
self.layer.cornerRadius = 10;
self.translatesAutoresizingMaskIntoConstraints = NO;
self.userInteractionEnabled = YES;
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[singleFingerTap setNumberOfTapsRequired:1];
[singleFingerTap setNumberOfTouchesRequired:1];
[self addGestureRecognizer:singleFingerTap];
return self; }
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
NSLog(@"Tappedddddddddd");
}
我已将Tap Gesture Recognizer添加到我的kOverlayNib.xib但由于某种原因我无法得到任何回复..它根本不起作用..
答案 0 :(得分:1)
@interface MyCustomView() <UIGestureRecognizerDelegate> @end
或您想写的任何地方。
singleFingerTap.delegate = self;
- (BOOL)gestureRecognizer:(UIGestureRecognizer )gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer)otherGestureRecognizer { return YES; }
现在您可以运行您的代码了。它有效。