Sam Shaikh Sam Shaikh - 8 months ago 113
Swift Question

Page menu with Hide navigation bar on Scroll

I want both menu in Navigation bar extension and hide the navigation bar except the extension when scrolling.

I was able to achieve menu with PageMenu "PageMenu" and hiding the navigation bar through AMScrollingNavbar

enter image description here

But the problem I am facing now is Nav bar hides but the views does not move up with nav bar

func loadControllers(){

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

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

topViewController.title = "TOP"

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

briefViewController.title = "BRIEFS"

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

videoViewController.title = "VIDEOS"

// Customize menu
parameters = [
.ViewBackgroundColor(UIColor(red: 20.0/255.0, green: 20.0/255.0, blue: 20.0/255.0, alpha: 1.0)),
.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)!),

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)



enter image description here

Call the Scroll method from the class thats added in the menu

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

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

change both line to like this it wont work because you are setting delegate for other instance instead of your navigation .

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

implement delgate in your controller and set origin of your view w.r.t your scrollview.