Sam Shaikh Sam Shaikh - 2 months ago 43
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!
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

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

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

Answer
    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.

Comments