简体   繁体   中英

SWRevealViewController panGesture issue - IOS/Swift

In my application I used SWRevealViewController in order to implement the side menu. There, for some reason I had to put a view which is embed in a navigation controller, before the reveal view controller.

This is my storyboard

在此处输入图片说明

Everything works fine other than one thing. when I drag from the left edge of the screen to the right side (pan gesture) on my home view, instead of side menu it navigates me to the previous view (in here case to the middle view which contains a button in the middle).

This is how it looks like when dragging

在此处输入图片说明

I want to avoid this and get the side menu when dragging like that. Can someone help me on this. Any help would be highly appreciated.

Edit:

This is the front_view and rear_view

在此处输入图片说明

You need to remove the popGesture from the navigation controller in any view controllers that you don't want to be able to use the swipe gesture:

  var gestureRecognizer: UIGestureRecognizer? {
    guard let nc = navigationController else { return nil }
    return nc.interactivePopGestureRecognizer
  }

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    if let gr = gestureRecognizer {
      gr.isEnabled = false
    }
  }

Take a ViewController.swift file for the initial ViewController having button.

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.navigationController?.interactivePopGestureRecognizer?.isEnabled = false

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

There is no issue in the swrevealviewcontroller implementation but the native behavior of navigation controller is causing this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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