我在我的代码中打开手势识别器时遇到了麻烦。我向点击手势识别器添加了一个 handleTap 回调,但打印语句从未发生。我只是没有运气。有人看到我在这里做错了吗?
在我的 ViewController.h
@interface ViewController : UIViewController<UITextFieldDelegate, UIGestureRecognizerDelegate> {
}
@end
这就是我在 ViewController.m 中的内容
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
View *myview = [[View alloc] initWithFrame:applicationFrame];
myview.userInteractionEnabled = YES;
myview.multipleTouchEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTap)];
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[myview addGestureRecognizer:tap];
self.view = myview;
}
-(void)handleTap:(UITapGestureRecognizer*)recognizer {
NSLog(@"dismiss keyboard");
//[usernameTextField resignFirstResponder];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return YES;
}
编辑:我添加了一个文本字段,当我单击文本字段时,我看到了分接选择器打印语句。但是,如果我点击文本字段,我不会得到选择器打印语句。