使用PageMenu和Storyboard Swift 3

时间:2017-04-11 15:01:34

标签: ios github swift3 cocoapods

我尝试使用this repo创建一个像你在Instagram上找到的PageMenu。我有滑动功能,但滚动菜单不会出现在导航栏下面。我看过Implementing PageMenu / initializing view controllers from storyboard,但它并没有真正帮助我解决问题。我也尝试使用repo中提供的demo并根据我的需要进行自定义,但是当我将它拖到我的项目时,它会省略滚动菜单。

这是我在viewControler中的代码:

    // Initialize view controllers to display and place in array
    var controllerArray : [UIViewController] = []

    let controller1 : TestTableViewController = TestTableViewController(nibName: "TestTableViewController", bundle: nil)
    controller1.parentNavigationController = self.navigationController
    controller1.title = "FAVOURITES"
    controllerArray.append(controller1)

    let controller2 : RecentsTableViewController = RecentsTableViewController(nibName: "RecentsTableViewController", bundle: nil)
    controller2.title = "RECIPES"
    controller2.parentNavigationController = self.navigationController
    controllerArray.append(controller2)


    // Customize menu (Optional)
    let parameters: [CAPSPageMenuOption] = [
        .menuItemSeparatorWidth(4.3),
        .scrollMenuBackgroundColor(UIColor.white),
        .viewBackgroundColor(UIColor(red: 247.0/255.0, green: 247.0/255.0, blue: 247.0/255.0, alpha: 1.0)),
        .bottomMenuHairlineColor(UIColor(red: 33/255.0, green: 161/255.0, blue: 77/255.0, alpha: 1)),
        .selectionIndicatorColor(UIColor(red: 33/255.0, green: 161/255.0, blue: 77/255.0, alpha: 1.0)),
        .menuMargin(20.0),
        .menuHeight(40.0),
        .selectedMenuItemLabelColor(UIColor(red: 33/255.0, green: 161/255.0, blue: 77/255.0, alpha: 1.0)),
        .unselectedMenuItemLabelColor(UIColor(red: 40.0/255.0, green: 40.0/255.0, blue: 40.0/255.0, alpha: 1.0)),
        .menuItemFont(UIFont(name: "HelveticaNeue-Medium", size: 14.0)!),
        .useMenuLikeSegmentedControl(true),
        .menuItemSeparatorRoundEdges(true),
        .selectionIndicatorHeight(2.0),
        .menuItemSeparatorPercentageHeight(0.1)
    ]

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

    // Optional delegate 
    pageMenu!.delegate = self

    self.view.addSubview(pageMenu!.view)
}

如果可以,请帮助我。提前致谢! :)

1 个答案:

答案 0 :(得分:3)

替换

pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRect(x: 0.0, y: 0.0, width: self.view.frame.width, height: self.view.frame.height), pageMenuOptions: parameters)

。通过

  pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRect(x: 0.0, y: 64, width: self.view.frame.width, height: self.view.frame.height), pageMenuOptions: parameters)

你必须给y到64,因为状态栏和导航栏覆盖了64个点。