在Scroll上隐藏导航栏的页面菜单

时间:2016-09-27 07:17:43

标签: ios swift uiscrollview uinavigationbar

我想在导航栏扩展中同时显示两个菜单,并在滚动时隐藏除扩展名之外的导航栏。

我能够通过PageMenu“PageMenu”获取菜单并隐藏导航栏AMScrollingNavbar

enter image description here

但我现在面临的问题是导航栏隐藏但视图不会向上移动导航栏

func loadControllers(){

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let topViewController = storyboard.instantiateViewControllerWithIdentifier("TopNewsController") as!
    TopNewsController

    topViewController.title = "TOP"
    controllerArray.append(topViewController)

    let briefViewController = storyboard.instantiateViewControllerWithIdentifier("BriefViewController") as!
    BriefViewController

    briefViewController.title = "BRIEFS"
    controllerArray.append(briefViewController)


    let videoViewController = storyboard.instantiateViewControllerWithIdentifier("VediosViewController") as!
    VediosViewController

    videoViewController.title = "VIDEOS"
    controllerArray.append(videoViewController)


    // Customize menu 
    parameters = [
        .ScrollMenuBackgroundColor(UIColor.navigationBarColor()),
        .ViewBackgroundColor(UIColor(red: 20.0/255.0, green: 20.0/255.0, blue: 20.0/255.0, alpha: 1.0)),
        .SelectionIndicatorColor(UIColor.whiteColor()),
        .BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)),
        .MenuItemFont(UIFont(name: "HelveticaNeue-Bold", size: 14.0)!),
        .MenuHeight(expressTribuneUtilities.convertIphone6ToIphone5(48)),
        .MenuItemWidth(90.0),
        .CenterMenuItems(true)
    ]


    AppDelegate.getInstatnce().nav = self.navigationController as! ScrollingNavigationController
    AppDelegate.getInstatnce().nav.scrollingNavbarDelegate = self


    // Initialize scroll menu
    pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 64.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)

    self.view.addSubview(pageMenu!.view)

}

enter image description here

从菜单中添加的类中调用Scroll方法

        AppDelegate.getInstatnce().nav.followScrollView(tableMainView, delay: 0.5)

1 个答案:

答案 0 :(得分:2)

        let navController = AppDelegate.getInstatnce().window?.rootViewController as! ScrollingNavigationController
    navController.scrollingNavbarDelegate = self

将这两行改为像这样它不会工作,因为你正在为其他实例而不是你的导航设置委托。

{{1}}

在您的控制器中实现delgate并设置您的视图的原点w.r.t your 滚动视图。