NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

SOLVED: Preventing master view 'sliding in' from left on right swipe gesture

Forums > iOS

I've got a UISplitViewController, but I don't want the master view 'sliding in' from the left edge of the screen when user makes a left to right swipe gesture, as I want that gesture to be exclusively used for drawing actions on a UIImageView canvas that's in the detail view controller.

I've got this code in the viewDidLoad of the detail view controller class:

let right = UISwipeGestureRecognizer(target : AppDelegate(), action : #selector(AppDelegate.rightSwipe))
right.direction = .right

and in my appDelegate class I've got:

@objc func rightSwipe(){
    guard let splitViewController = self.window?.rootViewController as? UISplitViewController else {
        fatalError("Missing SplitViewController")
    splitViewController.preferredDisplayMode = .primaryHidden

I can swipe left to right in the canvas and it will draw a line and not slide in the master view controller (as I intended). However, the line drawing of the user's gesture only lasts a short distance until the line drawing stops. I can make an upwardish movement and draw, say, an 'S' curve and just keep on draweing, with no problem. The problem only seems to manifest when I'm making an absolutley straight line from with a left to right swipe gesture.


In your split view controller, set presentsWithGesture = false.


Hacking with Swift is sponsored by NSSpain

SPONSORED Announcing NSSpain 2020: Remote Edition! An online, continuous conference for iOS developers. We’ll start on Thursday and finish on Friday, with talks, activities, and lots of fun for 36 hours, non-stop. Sound good? Join us!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

Not logged in

Log in

Link copied to your pasteboard.