2012-04-03 33 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 
} 

所以不得不上按鈕添加敲擊手勢。