0

使用带有图像按钮的显示隐藏 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 ;
        }
     }

这适用于隐藏键盘。但输入视图中的剩余区域也是可触摸的。如何避免这种情况。

4

1 回答 1

1

发生这种情况是因为您正在向整体添加点击手势,AccessoryView因此整个视图将响应点击手势,而不是仅向该图像按钮添加点击手势。

    kbdImage.userInteractionEnabled = YES;
    [kbdImage addGestureRecognizer:gestureRecogniser];
于 2013-02-15T12:17:59.760 回答