Search code examples
iosobjective-cswiftuigesturerecognizeruipangesturerecognizer

UIScreenEdgePanGestureRecognizer not working on orientation change?


I have a added a pan gesture recogniser for screen edge (left) edge. It is working well in portrait mode but in landscape orientation its not working.

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)

}

Solution

  • Don't add gesture recognizers to the window. The highest view with which you should be concerned is the window's rootViewController!.view. Even better, if this is view controller code, add it to self.view.