SWRevealViewController panGesture问题 - IOS / Swift

时间:2017-02-21 17:58:09

标签: ios swift uinavigationcontroller uipangesturerecognizer swrevealviewcontroller

在我的应用程序中,我使用了SWRevealViewController来实现侧面菜单。在那里,出于某种原因,我必须在显示视图控制器之前放置一个嵌入导航控制器的视图。

这是我的故事板

enter image description here

除了一件事以外,一切都很好。当我从我的主视图中的屏幕左边缘向右侧(平移手势)拖动时,它将导航到前一个视图(在这种情况下,中间视图包含中间的按钮),而不是侧面菜单

这是拖动时的样子

enter image description here

我希望避免这种情况,并在拖动时获取侧边菜单。有人可以帮我这个。任何帮助将受到高度赞赏。

修改

这是front_view和rear_view

enter image description here

2 个答案:

答案 0 :(得分:1)

您需要在任何您不希望使用滑动手势的视图控制器中从导航控制器中删除popGesture:

  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
    }
  }

答案 1 :(得分:1)

将ViewController.swift文件作为具有按钮的初始ViewController。

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.
    }
    */

}

swrevealviewcontroller实现中没有问题,但导航控制器的本机行为导致了此问题。