2012-04-03 63 views
1

我正在开发一个iPhone应用程序有一个购物车,我用UITableView来显示购物车。每个项目都有一个单元格,并且-tableFooterView被设置为自定义视图,该视图为用户提供了一个用于验证其信用卡CVV的文本字段以及一个用于完成结帐过程的按钮。UIButton在桌面页脚视图没有响应触摸时,键盘显示

当用户点击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事件。

从我所看到的情况看,任何被键盘覆盖的按钮都不会响应我的触摸(即使它从键盘后面滚动出来),直到键盘被解除。在键盘可见的情况下,在这个相同的-tableFooterView中未被键盘覆盖的按钮保持对触摸的响应。在iOS 5和iOS 4

运行

任何人都可以提供什么可能发生的情况有什么建议时

相同的行为?或者任何有用的疑难解答思路?

谢谢!

编辑 - 更新

事实上,被键盘覆盖的tableFooterView的部分不响应触摸事件。在我的自定义UIView子类中,我实现了-touchesBegan:withEvent:并且只记录发生了触摸。

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

另外我刚刚意识到,一旦我将该部分滚动到可见状态,被键盘覆盖的tableFooterView部分变为包含视图背景颜色的颜色。

+0

你有没有找到一些解决这个问题? – rishi 2017-09-04 16:10:36

+0

@ rishi你找到了解决办法吗? :) – vburojevic 2018-03-04 18:11:16

+0

@vburojevic是的,但解决方案有点奇怪:),我会张贴作为答案 – rishi 2018-03-05 15:19:20

回答

0

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

[self.theTableView bringSubviewToFront:yourUIButton]; 
1

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


- (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。

0

以下为我工作。

曾与按钮表视图页脚,对于按钮动作经由联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 
} 

所以不得不上按钮添加敲击手势。