【问题标题】:SWRevealViewController add gesture to a presented viewcontrollerSWRevealViewController 向呈现的视图控制器添加手势
【发布时间】:2019-12-10 11:55:20
【问题描述】:

我在我的项目中使用 SWRevealViewController,它运行良好,TableView 有 6 个选项,每次按下都会导致不同的 ViewController。

当我手动实例化另一个 ViewController(称为 viewControllerModelos)时,问题就出现了,这个 viewcontroller 没有链接到侧面菜单选项,但我确实需要从那个 viewcontroller 中也可以显示它。

我展示了正确实例化的 ViewController,但侧边菜单在滑动时没有出现,尽管我在那个 ViewController 中添加了手势

谁能告诉我怎么走?

下面的代码在显示侧边菜单的视图控制器中

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let viewControllerModelos = storyBoard.instantiateViewController(withIdentifier: "viewControllerModelos") as! VC_catalogo_modelos
        self.present(viewControllerModelos, animated: true, completion: nil)

下面的代码是实例化视图控制器的代码

import Foundation
import UIKit

class VC_catalogo_modelos: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        if revealViewController() != nil {
            self.view.addGestureRecognizer(revealViewController().panGestureRecognizer())
        }   
    }
}

【问题讨论】:

  • 您是从侧边栏推送 viewControllerModelos 控制器吗?还是来自其他地方?

标签: ios swift swrevealviewcontroller


【解决方案1】:

完美!非常感谢您的帮助,这对我有用。

    let sw  = revealViewController()
    // can place sw with revealViewCOntroller identifier
    self.view.window?.rootViewController = sw
    let viewControllerModelos = storyboard!.instantiateViewController(withIdentifier: "viewControllerModelos") as! VC_catalogo_modelos
    let navigationController = UINavigationController(rootViewController: viewControllerModelos)
    navigationController.navigationBar.isHidden=false
    navigationController.setNavigationBarHidden(true, animated: false)
    sw!.setFront(navigationController, animated: true)

【讨论】:

    【解决方案2】:

    目前你只是在展示 VC_catalogo_modelos 你没有设置 root 到revealViewController 因为这个原因在你的情况下没有任何工作

       let storyboard = UIStoryboard(name: "Main", bundle: nil)
                let sw = storyboard.instantiateViewController(withIdentifier: "sw") as! SWRevealViewController // can place sw with revealViewCOntroller identifier
                self.view.window?.rootViewController = sw
                let viewControllerModelos = storyBoard.instantiateViewController(withIdentifier: "viewControllerModelos") as! VC_catalogo_modelos
                let navigationController = UINavigationController(rootViewController: viewControllerModelos!) // using navigationController can help in future if there are other controller on action 
                navigationController.navigationBar.isHidden=false // unhide if you need navigationController bar
                navigationController.setNavigationTints()
    
                 sw.setFront(navigationController, animated: true)
                //pushFrontViewController(navigationController, animated: true) Use only if you require a push otherwise setFront
    

    【讨论】:

      猜你喜欢
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-10
      • 2023-03-18
      • 1970-01-01
      • 2015-07-16
      相关资源
      最近更新 更多