0

我正在创建一个 ios 应用程序,但问题是我不知道如何在没有登录屏幕的情况下成功登录后添加 sidemenu 我实现并成功工作,但是如何在登录屏幕后使用我无法理解,因为这是我的第一个应用程序我正在创建让我展示我的 sidemenu 代码

我正在将 KYDrawerController 用于 sidemenu

在 App Delegate 我是这样完成的

var drawer = KYDrawerController.init(drawerDirection: .left, drawerWidth: 260)

let storyBoard = UIStoryboard.init(name: "Main", bundle: Bundle.main)

        let mainVC = storyBoard.instantiateViewController(withIdentifier: "Screen2")
        let menuVC = storyBoard.instantiateViewController(withIdentifier: "Drawer")

        self.drawer.mainViewController = mainVC
        self.drawer.drawerViewController = menuVC

        self.window?.rootViewController = self.drawer
        self.window?.makeKeyAndVisible()

在 ViewController On Button Action 中,我像这样使用 appdelegate 中的那个

let appDel = UIApplication.shared.delegate as! AppDelegate
        appDel.drawer.setDrawerState(.opened, animated: true)

现在请告诉我点击登录按钮并登录成功后如何使用

在这里我直接设置mainVC但是登录时我不能设置因为我想在登录后显示sidemenu

我希望你理解我的问题请帮助莫如何做到这一点

供参考,我已使用此示例完成

https://www.youtube.com/watch?v=2Fo491yt4P0

4

1 回答 1

0
func setUpHomeVC() {
    var vc: UIViewController?
    let storyBoard = UIStoryboard.init(name: "Main", bundle: Bundle.main)
    if let user = AppHelper.getCurrentUser() { // if user is login in

        //this is slider menu VC
        let drawerViewController = storyBoard.instantiateViewController(withIdentifier: "Drawer")

        //this is homeVC
        let mainViewController   = storyBoard.instantiateViewController(withIdentifier: "Screen2")
        let drawerController     = KYDrawerController(drawerDirection: .left, drawerWidth: 0.8 * (UIScreen.main.bounds.width))
        let navController = UINavigationController(
            rootViewController: mainViewController)
        navController.view.backgroundColor = UIColor.white
        drawerController.mainViewController = navController
        drawerController.drawerViewController = drawerViewController
        self.window?.rootViewController = drawerController
    }else{
        vc = SignUpVC() // this is user login VC
        let mainVcIntial = UINavigationController(rootViewController:  vc!)
        mainVcIntial.isNavigationBarHidden = true
        self.window?.rootViewController = mainVcIntial
    }
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    self.window?.backgroundColor = UIColor.white
    setUpHomeVC()
    return true
}

希望这会帮助你。

于 2018-10-18T07:42:28.620 回答