コードでジェスチャ認識機能をオンにするだけで問題が発生します。タップ ジェスチャ認識エンジンに handleTap コールバックを追加しましたが、print ステートメントは発生しません。運が悪いだけです。ここで私が間違っていることを誰かが見ていますか?
私の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;
}
編集: テキスト フィールドを追加しました。テキスト フィールドをクリックすると、タップ セレクターの print ステートメントが表示されます。しかし、テキスト フィールドをタップすると、セレクターの print ステートメントが表示されません。