使用带有图像按钮的显示隐藏 iphone 键盘,该按钮位于键盘顶部。
[kbdImage setFrame:CGRectMake(290, 0, 30, 30)];
[accessoryView setFrame:CGRectMake(290, 0, 320, 30)];
UITapGestureRecognizer *gestureRecogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard:)];
gestureRecogniser.numberOfTapsRequired = 1;
[accessoryView addSubview:kbdImage];
[accessoryView addGestureRecognizer:gestureRecogniser];
for (UIView* v in searchBar.subviews) {
if ([v isKindOfClass:[UITextField class]]) {
((UITextField*)v).inputAccessoryView = accessoryView ;
}
}
这适用于隐藏键盘。但输入视图中的剩余区域也是可触摸的。如何避免这种情况。