我在頭文件中聲明裏面不起作用此:一個UITapGestureRecognizer使鍵盤皮,當我觸摸到一個UIButton
UITapGestureRecognizer* tap;
而且在viewDidLoad
:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(hideKeyboard)];
tap.enabled = NO;
[self.view addGestureRecognizer:tap];
}
我已經添加UITextFieldDelegate
,並添加這樣的:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
tap.enabled = YES;
return YES;
}
如果我碰到的任何地方Ø在鍵盤上,它會消失,但如果我在UIButton
中觸摸它並不會消失。
你知道爲什麼嗎?
看看[這裏](http://stackoverflow.com/questions/3344341/uibutton - 內 - 一 - 視圖 - 即-具有-A-uitapgesturerecognizer) – luiso1979