减少中心屏幕alpha时MMDrawerController错误

时间:2017-08-09 06:10:41

标签: ios swift mmdrawercontroller

我正在使用MMDrawerController在我的ios应用程序中创建侧边栏,我已经成功实现了它,但是我正在尝试在侧边栏显示时减少中心视图的alpha值,正如您通常在大多数具有类似功能的应用程序上看到的那样,但是我收到了错误

Type of expression is ambiguius without more context

以下是我的AppDelegate中的代码,visualstateblock部分正在抛出错误

func buildNavigationDrawer()
{

    // Instantiate Main.storyboard
    let mainStoryBoard:UIStoryboard = UIStoryboard(name:"Main", bundle:nil)

    // Create View Controllers
    let mainPage:TabBarViewController = mainStoryBoard.instantiateViewController(withIdentifier: "TabBarViewController") as! TabBarViewController



    let rightSideMenu:HomeSideMenuViewController = mainStoryBoard.instantiateViewController(withIdentifier: "HomeSideMenuViewController") as! HomeSideMenuViewController



    // Wrap into Navigation controllers

    let rightSideMenuNav = UINavigationController(rootViewController:rightSideMenu)

    // Cerate MMDrawerController
    drawerContainer = MMDrawerController(center: mainPage, rightDrawerViewController: rightSideMenuNav)

    //drawerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView
    drawerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.panningCenterView

    drawerContainer!.setDrawerVisualStateBlock { (drawerContainer, rightSideMenuNav) in
        drawerContainer!.centerViewController.view.alpha = 0.3;
    }
    // Assign MMDrawerController to our window's root ViewController
    window?.rootViewController = drawerContainer

}

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

setDrawerVisualStateBlock中,返回的MMDrawerController不是可选的,但背后仍有强制包装!

这告诉编译器从前一行(你创建的那一行)获取可选值

要解决此问题,请更改其中一个变量名称或使用此项:

drawerContainer?.setDrawerVisualStateBlock { $0.0.centerViewController.view.alpha = 0.3 }