【问题标题】:MDCBottomSheetController soft keyboard avoid pushing View upMDCBottomSheetController 软键盘避免向上推视图
【发布时间】:2019-06-19 13:58:41
【问题描述】:

我正在使用 MDCBottomSheetController

以下是我展示底部表单控制器的代码

 let bottomSheet: MDCBottomSheetController = MDCBottomSheetController(contentViewController: viewController)
    // Present the bottom sheet

    bottomSheet.shouldFlashScrollIndicatorsOnAppearance = true;
    if openFor == SearchBottomSheetViewController.OPEN_FOR_DATE {
        bottomSheet.preferredContentSize = CGSize(width: self.view.frame.size.width, height:  self.view.frame.size.height * 0.3)
    }else {
        bottomSheet.preferredContentSize = CGSize(width: self.view.frame.size.width, height: 3 * self.view.frame.size.height / 4)
    }

    // bottomSheet.dismiss(animated: <#T##Bool#>, completion: <#T##(() -> Void)?##(() -> Void)?##() -> Void#>)
    present(bottomSheet, animated: true, completion: nil)

当显示软键盘时,底部表单 ui 被向上推我不希望在显示键盘时 UI 被向上推

请参阅下面的 gif 以了解问题

【问题讨论】:

标签: ios swift bottom-sheet ios-keyboard-extension material-components-ios


【解决方案1】:

要成功实现这一点,请使用以下代码。 (只需在 viewDidLoad() 中添加 removeKeyboardObserver() 函数即可。)

func removeKeyboardObserver() {
    NotificationCenter.default.removeObserver(MDCKeyboardWatcher.shared()!)
}

func textViewDidEndEditing() {
    MDCKeyboardWatcher.load()
}

【讨论】:

    【解决方案2】:

    建议的解决方案

    增加文本字段顶部约束的常量。

    推理

    反复试验。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-04
      • 2020-07-25
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      • 1970-01-01
      相关资源
      最近更新 更多