如何调整输入附件视图的大小

时间:2013-02-15 12:14:25

标签: ios uisearchbar

使用带隐藏在键盘顶部的图像按钮的show hide 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 ;
        }
     }

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

1 个答案:

答案 0 :(得分:1)

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

    kbdImage.userInteractionEnabled = YES;
    [kbdImage addGestureRecognizer:gestureRecogniser];