aslanyanhaik / youtube-iOS

youtube iOS app template written in swift 5
MIT License
2.54k stars 573 forks source link

Why when we hide the navigationbar, the tabbar go to the top automatic? #6

Closed roshanman closed 7 years ago

roshanman commented 8 years ago

Why when we hide the navigationbar, the tabbar go to the top automatic?

aslanyanhaik commented 8 years ago

@roshanman sorry for late response. Yes, look for "hideBar" method which is hiding the navigation bar on swipe

roshanman commented 8 years ago

Thanks, I have noticed the method hideBar

func hideBar(notification: NSNotification)  {
        let state = notification.object as! Bool
        self.navigationController?.setNavigationBarHidden(state, animated: true)
}

In this method, we just hide the navigationbar, I don't understand why when we hide the navigationbar, the tabbar go to the top position automatic.

Thank you.

aslanyanhaik commented 8 years ago

it's done automatically by iOS. Once you hide the navbar, everything inside the main view goes up with animation.

roshanman commented 8 years ago

record

Why my button do not moved when i hide the navbar ?

aslanyanhaik commented 8 years ago

Hey @roshanman that's a good question. It depends how you build UI. If your constrains linked with NavBar then it will animate up, otherwise it will not move. Check the attachment. navBar.zip

roshanman commented 8 years ago

Thanks for your help. This method worked.

But in your code

lazy var tabBar: TabBar = {
    let tb = TabBar.init(frame: CGRect.init(x: 0, y: 0, width: globalVariables.width, height: 64))
    tb.delegate = self
    return tb
}()

//TabBar
self.view.addSubview(self.tabBar)

you do have not used constrains for tabbar. really strange!

aslanyanhaik commented 7 years ago

@roshanman yeah, it was a bad decision. In upcoming update will replace InitWithFrames with constrains