简体   繁体   English

UINavigationController向下滑动手势检测

[英]UINavigationController swipe down gesture detect

UINavigationController presented modally as form sheet can be swiped down to dismiss. 可以向下滑动以表单形式模态显示的UINavigationController来关闭它。 This gesture is native in iOS and not mine. 此手势是iOS中的本机手势,不是我的。 The problem is on iOS 13, it does not trigger viewWillAppear in the parent view controller after it gets dismissed. 问题出在iOS 13上,它被解雇后不会在父视图控制器中触发viewWillAppear。 So I need a way to know the view controller is getting dismissed or got dismissed by a system gesture. 因此,我需要一种方法来知道视图控制器正在被系统手势关闭或被关闭。 How do I detect dismissal of view controller in that case? 在这种情况下,如何检测视图控制器的解雇?

Looks like UIAdaptivePresentationControllerDelegate might be what you're looking for, specifically the 4 new instance methods. 看起来UIAdaptivePresentationControllerDelegate可能正是您想要的,特别是4个新实例方法。 Some more info here . 一些更多的信息在这里

You can use func didMove(toParent parent: UIViewController?) ,this can detect the dismissal of view controller.There is just one thing, it works too when the current viewController appears. 您可以使用func didMove(toParent parent: UIViewController?) ,这可以检测到视图控制器的关闭。只有一件事, 当当前viewController出现时它也可以工作。 So you will need a variable to eliminate interference like this: 因此,您将需要一个变量来消除这种干扰:

import UIKit

class ViewController: UIViewController {

    var isBack:Bool = false

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

    }

    override func didMove(toParent parent: UIViewController?) {
        super.didMove(toParent: parent)

        if isBack {
            //Dismiss.

        } else {
            isBack = true
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM