【问题标题】:Popping UIViewController with presented keyboard使用提供的键盘弹出 UIViewController
【发布时间】:2019-08-06 20:03:20
【问题描述】:

我在其中创建了带有 UIScrollView 的 UIViewController。在 UIScrollView 我添加了一些 UITextFields 用于数据输入。当其中一个 UITextFields 成为 firstResponder (键盘出现在屏幕上)并且我试图用滑动手势弹出这个 UIViewController 时,我有以下效果:

UIViewController 的视图正在下降,我可能会在当前 UIViewController 中看到以前 UIViewController 的部分。你有什么想法,如何解决这个问题?

【问题讨论】:

  • 能否请您发布用于弹出视图控制器的代码
  • @Stijnk008 我用滑动手势弹出它。为了启用它,添加了以下代码行:self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  • @IvanSuprynovich 问题是你看到了两个动画:当前视图控制器被弹出并且它的内容因为键盘试图隐藏而移动?这就是我所理解的。

标签: ios objective-c cocoa-touch uikit


【解决方案1】:

我发现当使用自定义后退操作时,交互式弹出手势停止工作。

要解决此问题,您可以将 interactivePopGestureRecognizer.delegate 属性设置为 nil。

试试这个:

class NavigationController: UINavigationController, UIGestureRecognizerDelegate {

    /// Custom back buttons disable the interactive pop animation
    /// To enable it back we set the recognizer to `self`
    override func viewDidLoad() {
        super.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = self
    }

    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return viewControllers.count > 1
    }
}

【讨论】:

    猜你喜欢
    • 2017-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-06
    相关资源
    最近更新 更多