【问题标题】:Scroll UITextField above Keyboard in a UITableViewCell on a regular UIViewController在常规 UIViewController 上的 UITableViewCell 中的键盘上方滚动 UITextField
【发布时间】:2017-10-22 23:28:48
【问题描述】:

我已经尝试过 StackOverflow 上的大部分示例。我也用过苹果的。我似乎遇到的问题是他们没有考虑 UITextField 在 UITableView 中。我已经多次这样做了,但不是这样。我有一个自定义的 UITableViewCell,里面有一个 UITextField。

在我的 UITableView(不是 UITableViewController)上,我需要能够避免将 UITextField 隐藏在 UITableView 下。

我现在有这个:

-(void)viewDidLoad
{
....
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];

....
}

- (void)scrollToRectOfTextField {
    UITableViewCell *cell = (UITableViewCell*)[self.activeTextField superview];
    CGRect r = CGRectMake(self.activeTextField.frame.origin.x,
                          cell.frame.origin.y+self.activeTextField.frame.origin.y,
                          self.activeTextField.frame.size.width,
                          self.activeTextField.frame.size.height);
    [self.tableView scrollRectToVisible:r animated:YES];
}

- (void)keyboardDidShow:(NSNotification *)notification
{
    if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone) {
        NSDictionary *userInfo = [notification userInfo];
        CGSize size = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
        NSLog(@"TableView: %@", NSStringFromCGRect(self.tableView.frame));
        CGRect newTableViewFrame = CGRectMake(self.tableView.frame.origin.x,
                                              self.tableView.frame.origin.y,
                                              self.tableView.frame.size.width, self.tableView.frame.size.height - size.height);
        self.tableView.frame = newTableViewFrame;
        NSLog(@"New TableView: %@", NSStringFromCGRect(self.tableView.frame));


        self.tableView.contentSize = CGSizeMake(self.tableView.contentSize.width, self.tableView.contentSize.height-size.height);
    }
}


- (void)keyboardWillHide:(NSNotification *)notification
{
    NSDictionary *userInfo = [notification userInfo];
    CGSize size = [[userInfo objectForKey: UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    self.tableView.frame = CGRectMake(self.tableView.frame.origin.x,
                                      self.tableView.frame.origin.y,
                                      self.tableView.frame.size.width,
                                      self.tableView.frame.size.height + size.height);

    NSLog(@"%@", NSStringFromCGRect(self.tableView.frame));
}


-(void)textFieldDidBeginEditing
{
     [self scrollToRectOfTextField];
}

这似乎在我的键盘上推了一堆空白。另请注意,我的 UITextField 上也有一个 inputAccessoryView。

哦,我不能使用任何第三方类。我喜欢 TPKeyboardAvoidingScrollView,但我不能使用任何第三方。

【问题讨论】:

  • 什么时候打电话给[self scrollToRectOfTextField];
  • 另外,如果您为 tableview 的底部边缘插入动画而不是尝试更改框架,您将获得更流畅的动画。
  • 这是个好问题。在我从中提取的示例中没有使用它。
  • 我编辑了它。它在 textFieldDidBeginEditing 中被调用。
  • 应该是- (void)textFieldDidBeginEditing:(UITextField *)textField - 你有没有在那里设置断点来查看它是否被调用?

标签: ios ios4


【解决方案1】:

我花了一整天的时间试图弄清楚这一点。我把它贴在这里,然后找到了一个博客链接和一个非常简单的解决方案。它看起来像这样:

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    CGPoint pointInTable = [textField.superview convertPoint:textField.frame.origin toView:self.tableView];
    CGPoint contentOffset = self.tableView.contentOffset;

    contentOffset.y = (pointInTable.y - textField.inputAccessoryView.frame.size.height);

    NSLog(@"contentOffset is: %@", NSStringFromCGPoint(contentOffset));

    [self.tableView setContentOffset:contentOffset animated:YES];

    return YES;
}


-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [textField resignFirstResponder];

    if ([textField.superview.superview isKindOfClass:[UITableViewCell class]])
    {
        UITableViewCell *cell = (UITableViewCell*)textField.superview.superview;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddle animated:TRUE];
    }

    return YES;
}

Check this for iOS 8

【讨论】:

  • 我让它工作了,但我必须删除 ShouldEndEditing 的 If 语句。此外,如果您需要像我一样拥有多个文本字段,您还必须实现 textFieldDidBeginEditing 和 textFieldDidEndEditing。只需复制并粘贴与 ShouldBegin 和 ShouldEnd 相同的代码即可。这将允许用户在保持相同功能的同时从 textField 跳转到 textField。如果您在使用 NSIndexPath 时遇到困难,这里有一种与任何版本的 iOS 兼容的方法:stackoverflow.com/questions/9577392/…
  • 不要使用超级视图链。这不是可靠的设计。改用 indexPaths 和 textField 视图标签的字典,查找下一个响应者是哪个文本字段并使其成为 firstResponder。
  • 如果您在文本字段上调用 ​​becomeFirstResponder 而不是点击它,这将不起作用。
  • 如果我们在多个子视图中使用文本字段怎么办?
  • 同意@EugeneProkoshev。这段代码很糟糕。虽然它有很多点,甚至被接受。如果 Apple 在未来的 iOS 中更改其 tableview 子视图层次结构,则此代码肯定会中断(即崩溃应用程序)。
【解决方案2】:

我尝试了@inturbidus 为 iOS8 发布的链接,但不幸的是它对我不起作用。经过一番挖掘,事实证明 Apple 在他们的网站上确实有示例代码,可以像在 UITableViewController 中一样自然地完成这项工作。这是 Objective-C 版本的 Apple 链接,我也在此处添加 swift 版本。

来自 Apple 的 Objective-C 链接(滚动至清单 5-1): https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

Objective-C 版本的 Swift 改编

var activeField: UITextField?

func textFieldDidBeginEditing(textField: UITextField) {
    self.activeField = textField
}

func textFieldDidEndEditing(textField: UITextField) {
    self.activeField = nil
}

func registerForKeyboardNotifications() {
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardDidShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillBeHidden:", name: UIKeyboardWillHideNotification, object: nil)
}    

func keyboardWasShown(aNotification: NSNotification) {
    let info = aNotification.userInfo as! [String: AnyObject],
    kbSize = (info[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue().size,
    contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: kbSize.height, right: 0)

    self.tableView.contentInset = contentInsets
    self.tableView.scrollIndicatorInsets = contentInsets

    // If active text field is hidden by keyboard, scroll it so it's visible
    // Your app might not need or want this behavior.
    var aRect = self.view.frame
    aRect.size.height -= kbSize.height

    if !CGRectContainsPoint(aRect, activeField!.frame.origin) {
        self.tableView.scrollRectToVisible(activeField!.frame, animated: true)
    }
}

func keyboardWillBeHidden(aNotification: NSNotification) {
    let contentInsets = UIEdgeInsetsZero
    self.tableView.contentInset = contentInsets
    self.tableView.scrollIndicatorInsets = contentInsets
}

【讨论】:

  • 我没有添加链接,@Hector 做了。
  • 我知道这是一个旧答案,但我想为遇到此问题的任何人补充:我的 tableview 没有覆盖到底部的整个视图我不得不稍微更正 kbSize.height边距,因为只有 UITableView 的一部分被键盘覆盖。如果我使用此解决方案,该行会从 UITableView 中滚动出来并且不可见。所以keyboardWasShow 中的这一行contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: kbSize.height, right: 0) 更改为UIEdgeInsets(top: 0, left: 0, bottom: kbSize.height-margin, right: 0)
【解决方案3】:

我混合了 MattSalman 的答案。 这适用于 tableView 中的许多文本字段。 斯威夫特 3

基本上是获取 textInput 的 BOTTOM Y 点。一旦我们有了它,我检查键盘是否覆盖了 textInput,如果这样做,我将更改 tableView 的 contentOffset

首先注册通知。在 init 中如果是 UIView 或在 viewDidLoad 中如果是 UIViewController:

    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
    NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)

然后将触摸的文本字段设置为当前输入

var inputActive: UITextField!

func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
    inputActive = textInput
    return true
}

最后实现通知方法:

func keyboardWillShow(notification: NSNotification) {
    var userInfo = notification.userInfo!
    if let keyboardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
        // Get my height size
        let myheight = tableView.frame.height
        // Get the top Y point where the keyboard will finish on the view
        let keyboardEndPoint = myheight - keyboardFrame.height
        // Get the the bottom Y point of the textInput and transform it to the currentView coordinates.
        if let pointInTable = inputActive.superview?.convert(inputActive.frame.origin, to: tableView) {
            let textFieldBottomPoint = pointInTable.y + inputActive.frame.size.height + 20
            // Finally check if the keyboard will cover the textInput
            if keyboardEndPoint <= textFieldBottomPoint {
                tableView.contentOffset.y = textFieldBottomPoint - keyboardEndPoint
            } else {
                tableView.contentOffset.y = 0
            }
        }
    }
}

func keyboardWillHide(notification: NSNotification) {
    tableView.contentOffset.y = 0
}

要添加的东西很少。 padding 是我在我的案例中添加的一些额外距离,即 20 点。 同样在我的情况下,UITableView 被添加到 UIViewController 但这也应该在 UITableViewController 中工作

希望这会有所帮助!

【讨论】:

  • 我认为多解释一下你的代码是如何工作的以及它在做什么会对你有所帮助。
  • @GrumpyCrouton 感谢您的建议。我在代码上添加了一些 cmets,并对我的工作进行了一些解释。 =]
  • 谢谢,我们使用了一个包含许多部分和行的表格。我改变了: var inputActive: UITextView!还有这个: func textViewShouldBeginEditing(_ textView: UITextView) -> Bool { inputActive = textView return true }
【解决方案4】:

感谢@Salman 提供链接。
请注意,Apple 示例用于普通视图中的滚动视图。
在表格视图中,您必须将 ActiveField 的 Point 和 Rect 转换为表格的坐标,所以我在函数 keyboardWasShown 中更改了一些行:

func keyboardWasShown(aNotification: NSNotification) {
        let info = aNotification.userInfo as! [String: AnyObject],
        kbSize = (info[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue().size,
        contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: kbSize.height, right: 0)

        self.tableBasket.contentInset = contentInsets
        self.tableBasket.scrollIndicatorInsets = contentInsets

        var aRect = self.view.frame
        aRect.size.height -= kbSize.height

        let pointInTable = activeField!.superview!.convertPoint(activeField!.frame.origin, toView: tableView)
        let rectInTable = activeField!.superview!.convertRect(activeField!.frame, toView: tableView)

        if !CGRectContainsPoint(aRect, pointInTable) {
            self.tableView.scrollRectToVisible(rectInTable, animated: true)
        }
}

如果您的视图有 tabBarController,请记住使用 tabBar 高度而不是 UIEdgeInsetsZero 重置 contentInsets(如果没有,您的最后一行可能隐藏在 tabBar 下):

func keyboardWillBeHidden(aNotification: NSNotification) {
        //UIEdgeInsetsZero is used in view without tabBar
        //let contentInsets = UIEdgeInsetsZero
        let tabBarHeight = self.tabBarController!.tabBar.frame.height
        let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: tabBarHeight, right: 0)
        self.tableView.contentInset = contentInsets
        self.tableView.scrollIndicatorInsets = contentInsets
    }
}

【讨论】:

  • 谢谢。我已将代码重写为 Obj-C,它解决了使用 tableview 时 Apple 代码的问题。
  • 顺便说一句:如果您使用 self.edgesForExtendedLayout = UIRectEdgeNone 那么没有必要像这里提到的那样更改keyboardWillBeHidden
【解决方案5】:

我的解决方案(适用于 Xcode 8.3.3、Swift 3、iOS 10.3.1):

class MyTableViewController: UITableViewController {

    override func viewWillAppear(_ animated: Bool) {
        NotificationCenter.default.addObserver(self, selector: #selector(actionKeyboardDidShow(with:)), name: .UIKeyboardDidShow, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(actionKeyboardWillHide(with:)), name: .UIKeyboardWillHide, object: nil)
    }

    override func viewDidDisappear(_ animated: Bool) {
        NotificationCenter.default.removeObserver(self, name: .UIKeyboardDidShow, object: nil)
        NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)
    }

    @objc private func actionKeyboardDidShow(with notification: Notification) {
        guard let userInfo = notification.userInfo as? [String: AnyObject],
            let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
            else { return }

        var contentInset = self.tableView.contentInset
        contentInset.bottom += keyboardFrame.height

        self.tableView.contentInset = contentInset
        self.tableView.scrollIndicatorInsets = contentInset
    }

    @objc private func actionKeyboardWillHide(with notification: Notification) {
        guard let userInfo = notification.userInfo as? [String: AnyObject],
            let keyboardFrame = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
            else { return }

        var contentInset = self.tableView.contentInset
        contentInset.bottom -= keyboardFrame.height

        self.tableView.contentInset = contentInset
        self.tableView.scrollIndicatorInsets = contentInset
    }

}

【讨论】:

  • 我认为您希望在 DidShow 中使用 UIKeyboardFrameEndUserInfoKey。 Begin 是动画开始时的帧
【解决方案6】:

我混合了@Victor 的答案和我拥有的一些代码。 我创建了一个方便的扩展,可以在许多 UITextField 中使用。

1.- 首先我们需要一个UITextField的扩展来管理键盘通知

extension UITextField {

    func keepTextFieldAboveKeyboard(tableView:UITableView) {

        var willShowNotification: NSObjectProtocol?
        var willHideNotification: NSObjectProtocol?

        willShowNotification = NotificationCenter.default.addObserver(forName: NSNotification.Name.UIKeyboardWillShow, object: nil, queue: OperationQueue.main) {(notification) in

            var userInfo = notification.userInfo!

            if let keyboardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
                // Get my height size
                let myheight = tableView.frame.height
                // Get the top Y point where the keyboard will finish on the view
                let keyboardEndPoint = myheight - keyboardFrame.height
                // Get the the bottom Y point of the textInput and transform it to the currentView coordinates.
                if let pointInTable = self.superview?.convert(self.frame.origin, to: tableView) {

                    let textFieldBottomPoint = pointInTable.y + self.frame.size.height + 20

                    // Finally check if the keyboard will cover the textInput
                    if keyboardEndPoint <= textFieldBottomPoint {

                        tableView.contentOffset.y = textFieldBottomPoint - keyboardEndPoint
                    } else {

                        tableView.contentOffset.y = 0
                    }
                }
            }

            NotificationCenter.default.removeObserver(willShowNotification!)
        }

        willHideNotification = NotificationCenter.default.addObserver(forName: NSNotification.Name.UIKeyboardWillHide, object: nil, queue: OperationQueue.main) { (notification) in

            tableView.contentOffset.y = 0

            NotificationCenter.default.removeObserver(willHideNotification!)
        }

    }

}

2.- 应该在 textFieldShouldBeginEditing 中调用之前的扩展,这样我们也可以有一个扩展

extension UITextField : UITextFieldDelegate {

    public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool  {

        guard let tableView = textField.parentView(of: UITableView.self) else { return true };

        textField.keepTextFieldAboveKeyboard(tableView:tableView);

        return true;

    }
}

3.- 最后,正如您在前面的方法中注意到的那样,我们需要 TableView,其中包含 UITextField 的单元格所在的位置。所以我们可以使用这个扩展(这对于其他目的也很有用)

extension UIView {
    func parentView<T: UIView>(of type: T.Type) -> T? {
        guard let view = self.superview else {
            return nil
        }
        return (view as? T) ?? view.parentView(of: T.self)
    }
}

4.- 最后在UITextField所在的单元格,我们只写这行简单的代码

textField.delegate = textField;

完全可重复使用且通用。

【讨论】:

    【解决方案7】:

    此答案适用于 Xamarin iOS 用户,但有人可以轻松修改它以使其与 Swift 或 Objective C 一起使用。

    解决方案非常简单,并且在我需要一个单元格出现在屏幕上半部分以使单元格的文本字段位于键盘上方的情况下非常有效。所以我所做的如下:

    我通过以下方式实现了 textField.ShouldBeginEditing:

    myTextField.ShouldBeginEditing = textField =>
    {
       myTableView.ScrollToRow(indexPath, UITableViewScrollPosition.Top, true);
    
       return true;
    };
    

    地点:

    myTextField 是单元格的文本字段,

    myTableView是表格视图,

    indexPath 是表格视图中单元格的索引路径。

    正如我之前提到的,这个解决方案在我的情况下非常有效,所以我想我可以与你们分享它,以防它也适用于你。快乐编码:)

    【讨论】:

      【解决方案8】:

      jqgsninimo 的解决方案已更新至 4.2。适用于 iOS 12.0。

      斯威夫特 4.2

      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
          NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow(with:)), name: UIResponder.keyboardDidShowNotification, object: nil)
          NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(with:)), name: UIResponder.keyboardWillHideNotification, object: nil)
      }
      
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
          NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidShowNotification, object: nil)
          NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
      }
      
      @objc func keyboardDidShow(with notification: Notification) {
          guard let userInfo = notification.userInfo as? [String: AnyObject],
              let keyboardFrame = (userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
              else { return }
      
          var contentInset = self.tableView.contentInset
          contentInset.bottom += keyboardFrame.height
      
          tableView.contentInset = contentInset
          tableView.scrollIndicatorInsets = contentInset
      }
      
      @objc func keyboardWillHide(with notification: Notification) {
          guard let userInfo = notification.userInfo as? [String: AnyObject],
              let keyboardFrame = (userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue
              else { return }
      
          var contentInset = self.tableView.contentInset
          contentInset.bottom -= keyboardFrame.height
      
          tableView.contentInset = contentInset
          tableView.scrollIndicatorInsets = contentInset
      }
      

      【讨论】:

      • 这只会为键盘添加内容插入,这意味着您可以滚动到 tablview 的底部而无需退出键盘。但它没有任何代码用于关注活动文本字段。
      【解决方案9】:

      在常规 UIViewController swift 3 和 Xcode 8.1 上的 UITableViewCell 中的键盘上方滚动 UITextField

      1) 设置委托 = UITextFieldDelegate

        override func viewWillAppear(_ animated: Bool) {
      
              NotificationCenter.default.addObserver(self, selector: #selector(DayViewController.keyboardWillShow), name:NSNotification.Name.UIKeyboardWillShow, object: nil);
              NotificationCenter.default.addObserver(self, selector: #selector(DayViewController.keyboardWillHide), name:NSNotification.Name.UIKeyboardWillHide, object: nil);
      
         }
            func textFieldDidBeginEditing(_ textField: UITextField) {
                self.activeField = textField
         }
            func textFieldDidEndEditing(_ textField: UITextField) {
              self.activeField = nil
         }
      
      
      //MARK: - Keyboard Show and Hide Methods
          func keyboardWillShow(notification: NSNotification)
          {
              let info = notification.userInfo! as! [String: AnyObject],
              kbSize = (info[UIKeyboardFrameBeginUserInfoKey] as! NSValue).cgRectValue.size,
              contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: kbSize.height, right: 0)
      
              self.FourthTblMainTableView.contentInset = contentInsets
              self.FourthTblMainTableView.scrollIndicatorInsets = contentInsets
      
              var aRect = self.FourthTblMainTableView.frame
              aRect.size.height -= kbSize.height
          }
          func keyboardWillHide(notification: NSNotification)
          {
               let contentInsets = UIEdgeInsets.zero
              self.FourthTblMainTableView.contentInset = contentInsets
              self.FourthTblMainTableView.scrollIndicatorInsets = contentInsets
          }
      

      【讨论】:

        【解决方案10】:

        将@Matt Hudsons 转换为 Swift 4.2 的答案并通过委托进行改进:

        func cell(_ cell: UITableViewCell, willStartEditing view: UIView) {
            if let inputAccessoryViewHeight = view.inputAccessoryView?.frame.size.height {
                var contentOffset = self.tableView.contentOffset
                let pointInTable = view.convert(view.frame.origin, to: self.tableView)
                
                contentOffset.y = pointInTable.y - inputAccessoryViewHeight
                
                self.tableView.setContentOffset(contentOffset, animated: true)
            }
        }
        
        func cell(_ cell: UITableViewCell, willEndEditing view: UIView) {
            view.resignFirstResponder()
            
            if let position = self.tableView.indexPath(for: cell) {
                self.tableView.scrollToRow(at: position, at: .middle, animated: true)
            }
        }
        

        在你的 UITableViewCell 中实现 UITextFieldDelegate 并像下面这样传递 UITextField:

        func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
            delegate?.cell(self, willStartEditing: textField)
            return true
        }
        
        func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
            delegate?.cell(self, willEndEditing: textField)
            return true
        }
        

        【讨论】:

          【解决方案11】:

          swift4中,我们可以创建UIViewControllerextension

          extension UIViewController {
              //MARK: Keyboard user interactions
              func handleContainerViewFrameOnKeyboardShowHide(originalContainerFrame: CGRect) {
                  NotificationCenter.default.addObserver(forName: NSNotification.Name.UIKeyboardWillShow, object: nil, queue: OperationQueue.main) {(notification) in
                      var info = (notification as NSNotification).userInfo!
                      let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
                      var tableViewFrame = originalContainerFrame
                      tableViewFrame.size.height = originalContainerFrame.size.height - keyboardFrame.size.height
                      self.view.frame = tableViewFrame
                  }
                  NotificationCenter.default.addObserver(forName: NSNotification.Name.UIKeyboardWillHide, object: nil, queue: OperationQueue.main) { (notification) in
                      self.view.frame = originalContainerFrame
                  }
              }
          }
          

          【讨论】:

          • 这个扩展怎么用?
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-30
          • 1970-01-01
          • 1970-01-01
          • 2018-06-12
          • 1970-01-01
          相关资源
          最近更新 更多