UIScreenEdgePanGestureRecognizer 无法处理方向更改?

UIScreenEdgePanGestureRecognizer not working on orientation change?

我为屏幕边缘(左)边缘添加了一个平移手势识别器。它在纵向模式下运行良好,但在横向模式下不起作用。

override init() {
    super.init()
    //Pan Gesture for dragging Screen Edge
    let panGestureFromScreenEdge = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(panFromSide(sender:)))
    panGestureFromScreenEdge.edges = .left
    UIApplication.shared.keyWindow?.addGestureRecognizer(panGestureFromScreenEdge)

}

不要向 window 添加手势识别器。您应该关注的最高视图是 window 的 rootViewController!.view。更好的是,如果这是视图控制器代码,请将其添加到 self.view.