Iphone 显示键盘时,表尾视图中的UIButton不响应触摸

Iphone 显示键盘时,表尾视图中的UIButton不响应触摸,iphone,ios,uitableview,uiview,uiscrollview,Iphone,Ios,Uitableview,Uiview,Uiscrollview,我正在开发一个iPhone应用程序,它有一个购物车,我正在使用UITableView来显示购物车。每个项目都有一个单元格,-tableFooterView设置为自定义视图,该视图为用户提供一个文本字段以验证其信用卡的CVV,并提供一个按钮以完成结账过程 当用户点击CVV文本字段时,我会调整表格视图的大小,以便键盘不会覆盖任何内容 - (void)keyboardWillShow:(NSNotification *)n { // I'll update this to animate

我正在开发一个iPhone应用程序,它有一个购物车,我正在使用UITableView来显示购物车。每个项目都有一个单元格,
-tableFooterView
设置为自定义视图,该视图为用户提供一个文本字段以验证其信用卡的CVV,并提供一个按钮以完成结账过程

当用户点击CVV文本字段时,我会调整表格视图的大小,以便键盘不会覆盖任何内容

- (void)keyboardWillShow:(NSNotification *)n
{   
    // I'll update this to animate and scroll the view once everything works 
    self.theTableView.frameHeight = self.view.frameHeight - KEYBOARD_HEIGHT_PORTRAIT_IPHONE;
}
输入CVV后,用户可以点击完成键关闭键盘:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return NO;
}
然而,所有这些都可以工作,当键盘可见时,我的签出按钮(一个普通的UIButton)不会对触摸事件做出响应。表格滚动,但按钮的touchUpInside事件从未触发

一旦我点击“完成”并关闭键盘,签出按钮将识别touchUpInside事件

从我所看到的情况来看,似乎任何被键盘覆盖的按钮都不会响应我的触摸(即使它从键盘后面滚出来),直到键盘被关闭。当键盘可见时,此同一-TableFooter视图中未被键盘覆盖的按钮仍能对触摸做出响应

在iOS 5和iOS 4上运行时的行为相同

有人能对可能发生的事情提出任何建议吗?或者有什么有用的故障排除方法

谢谢

编辑-更新

事实上,键盘覆盖的TableFooter视图部分没有响应触摸事件。在我的自定义UIView子类中,我实现了
-touchesbreated:withEvent:
,并记录发生的触摸

在显示键盘之前,触摸视图中的任何位置都会得到日志语句。但是,调整tableview的大小后,仅触摸视图的上部会生成日志语句


另外,我刚刚意识到,当我滚动显示TableFooter视图中被键盘覆盖的部分时,该部分将变为包含视图的背景色。

我认为调整
UITableView
的大小会导致它将
UIButton
(子视图)发送到视图层次结构的后面。调整帧大小后,可能需要将其显式置于前面

[self.theTableView bringSubviewToFront:yourUIButton];

我认为调整
UITableView
的大小会导致它将
UIButton
(子视图)发送到视图层次结构的后面。调整帧大小后,可能需要将其显式置于前面

[self.theTableView bringSubviewToFront:yourUIButton];

我也有同样的问题。我认为这是iOS中的一个bug,但我发现了一个解决方法:


- (void)keyboardWillShow:(NSNotification *)note {
    NSDictionary* userInfo = [note userInfo];

    // get the size of the keyboard
    NSValue *boundsValue = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [boundsValue CGRectValue].size; // screen size
    CGFloat keyboardHeight;
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait || 
        self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        keyboardHeight = keyboardSize.height;
    } else {
        keyboardHeight = keyboardSize.width;
    }

    // resize the view with the keyboard
    __block CGRect origFrame = self.view.frame;
    __block CGRect viewFrame = origFrame;
    viewFrame.size.height -= keyboardHeight - ((self.tabBarController != nil) ? self.tabBarController.tabBar.frame.size.height : 0);
    // Set the height to zero solves the footer view touch events disabled bug
    self.view.frame = CGRectMake(origFrame.origin.x, origFrame.origin.y,
                                 viewFrame.size.width, 0);
    // We immediately set the height back in the next cycle, before the animation starts
    dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        self.view.frame = origFrame; // The original height
        // start the animation
        [UIView animateWithDuration:0.4 animations:^{
            [self.view setFrame:viewFrame];
        }];
    });
}
诀窍是将tableView的高度设置为0,并在下一个运行周期中恢复到原始高度


这对我的iOS 4.3和5.1都有效。

我也有同样的问题。我认为这是iOS中的一个bug,但我发现了一个解决方法:


- (void)keyboardWillShow:(NSNotification *)note {
    NSDictionary* userInfo = [note userInfo];

    // get the size of the keyboard
    NSValue *boundsValue = [userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [boundsValue CGRectValue].size; // screen size
    CGFloat keyboardHeight;
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait || 
        self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
        keyboardHeight = keyboardSize.height;
    } else {
        keyboardHeight = keyboardSize.width;
    }

    // resize the view with the keyboard
    __block CGRect origFrame = self.view.frame;
    __block CGRect viewFrame = origFrame;
    viewFrame.size.height -= keyboardHeight - ((self.tabBarController != nil) ? self.tabBarController.tabBar.frame.size.height : 0);
    // Set the height to zero solves the footer view touch events disabled bug
    self.view.frame = CGRectMake(origFrame.origin.x, origFrame.origin.y,
                                 viewFrame.size.width, 0);
    // We immediately set the height back in the next cycle, before the animation starts
    dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        self.view.frame = origFrame; // The original height
        // start the animation
        [UIView animateWithDuration:0.4 animations:^{
            [self.view setFrame:viewFrame];
        }];
    });
}
诀窍是将tableView的高度设置为0,并在下一个运行周期中恢复到原始高度


这在iOS 4.3和5.1中对我都适用。

以下内容对我很有效

有一个带有按钮的表视图页脚,该按钮操作通过xib链接,除了添加了以下代码之外-

@IBOutlet private weak var myButton: CustomUIButton!

override public func awakeFromNib() {
    super.awakeFromNib()

    let myButtonTapGesture = UITapGestureRecognizer(target: self, action: #selector(myButtonAction(_:)))
    myButton.addGestureRecognizer(myButtonTapGesture)
}

@IBAction func myButtonAction(_ sender: AnyObject) {
    // button action implementation
}

因此,我必须在按钮上添加一个点击手势。

下面的操作对我来说很有效

有一个带有按钮的表视图页脚,该按钮操作通过xib链接,除了添加了以下代码之外-

@IBOutlet private weak var myButton: CustomUIButton!

override public func awakeFromNib() {
    super.awakeFromNib()

    let myButtonTapGesture = UITapGestureRecognizer(target: self, action: #selector(myButtonAction(_:)))
    myButton.addGestureRecognizer(myButtonTapGesture)
}

@IBAction func myButtonAction(_ sender: AnyObject) {
    // button action implementation
}

因此,我必须在按钮上添加一个点击手势。

您找到解决方法了吗?@rishi您找到解决方法了吗?:)@vburojevic是的,但解决方案有点奇怪:),我会把它作为一个回答,你找到了一些解决方法吗?@rishi你找到了解决方法吗?:)@vburojevic是的,但解决方案有点奇怪:),我将把它作为一个答案发布