I need to hide the navigation bar when the user scrolls down. Currently, I'm calling setNavigationBarHidden: YES animated:YES on scroll, but this solution isn't ideal as it makes the main view jump up as soon as the animation is called.
The Instagram app has a much better solution - the navigation bar is locked to the top of the main view, and it scrolls up as the user scrolls. Scroll down a few pixels, and only part of the nav bar gets hidden.
Any ideas on how this could be accomplished?
Check out https://github.com/andreamazz/AMScrollingNavbar.
Its very easy to use, just subclass AMScrollingNavbar in your viewController
I don't think they are using a navigation bar. I think it's custom header view for the UITableView, or at least that's what I would do since you can put any UIView there.
You can use the UITableView delegate to set those headers.
navigation bar doesn't provide this function. the best way is to use a custom view (your custom navigation bar) as a subview of the main view, then do the animations yourself, using functions like [UIView animateWithDuration ....] with translation function using something like CATransform3DTranslate
I have found exactly the way Instagram did it - check out my answer here
No pan gesture recognizers, setting bars hidden, nothing like that, just some cool engineering inside scrollViewDidScroll delegate method of the table view
Related
I have an app built from the UITabBarController starter project. The first tab is part of the main.xib that contains the tab bar. I would like to slide a view up from the bottom on top of that tab's view that only covers part of the screen. My understanding is that you can only cover part of the screen if you make the top view non-modal, but I don't see a way to do that without a NavigationController.
How can I do this?
you can add a UIView as a subview to the current view, and then animate its appearance into the screen using animation blocks, or Quartz or however you would like.
presentModalViewController: is actually a method that belongs to UIViewController, the superclass of UINavigationController, so you can use it from any view controller, not just a navigation controller.
Have you tried using a UIActionSheet? That's an easy way to get a view with a few buttons for user input to slide up and only cover the bottom portion of the current view.
I have a tableview with a navigation bar at the top. I've added text to the prompt property of the navigation bar. This cuts the top half of the first tableview cell. Is there a way to tell the tableview that the prompt is present or do I need to roll something custom?
If you are using a navigation bar independent of UINavigationController, then you will need to roll your own custom solution. You may want to consider switching to using UINavigationController.
If you are using UINavigationController with UITableViewController, this should happen automatically for you. Even if you are using UIViewController with a UITableView as the view, this should still happen automatically for you - provided that you set the autoresizingMask of the tableView appropriately.
I have a custom UITabBarController and I want it to slide out the old view and slide in the new view whenever a TabBarItem gets pressed. I looked at UITabBarControllerDelegate but it just offers me to decide if the view gets displayed not how (via shouldSelectViewController).
Is there a way to do that?
(My goal is to have a starfield background that looks almost the same on all the 4 views. It should look like the items get changed and the background just scrolls by a little)
Subclass UITabBarController and make it it's own delegate. Now you can intercept methods like tabBarController:shouldSelectViewController: and manipulate any custom views you have added to the tab bar. And if you add your starfield to the tab bar view, and then use tab controllers that have translucent views the common background can show through.
And you can even intercept tab bar controller methods directly like setSelectedIndex: to have even more control to let you fade things out. But just make sure that you call the super version of the method at some point if you do this so the tab bar remains functional.
i need to shrink the height of a UINavigationBar (attached to the UINavigationController)
i've done this via the UINavigationControllerDelegate's navigationController:didShowViewController method, and it's working fine.
the problem is the visible viewcontroller that's in the main view. it wasn't resizing itself to reflect the new navbar height. thus, the didShowViewController method also resizes the viewcontroller's view frame, which works fine.
however, when i go to push on a new ViewController, or pop, i always see the view shift down to the original position during the animated transition to the next view. then, due to the code i have in the didShowViewController in the NavControllerDelegate, it shifts it back up.
i'm curious as to the best way to ensure that the shift down never happens.
i tried placing the code that resizes the frame into the willShowViewController, but that doesn't do anything.
i've also made sure that the UIView's frame that is the view of the UIViewController that's being popped, is also of the proper/shifted dimensions. no go there.
it's like i need to intercept the drawing actions after the pushViewController is invoked, and before the UINavigationController's didShowViewController is called.
i've been staring at my code for hours & hours... not getting anywhere. hopefully this makes sense to someone out there.
thanks!!!
Another option I think would be to set the NavigationControllers navigationBarHidden equal to YES. This will hide the nav bar completely and then you can then draw whatever view you want in the place the bar would have resided. Just put controls on the view that wrap the navigation methods (push, pop, etc...). It might be a challenge to get it to have the same style as a nav bar though.
Within Interface Builder, I have the following
UIViewController
-- View
---- TableView
In my UIViewController I have set
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
I also have other view controllers that are in IB. What am I missing here? The only way I can get it to rotate is if I use the transform method.
Are you using the tableview in a tab-based app by any chance? In case you are, you can only get a view to support landscape mode if all the viewcontrollers of the tabbar controller support landscape mode.
Other than that, I don't see any reason why your view should not support landscape mode.
The problem is with the autosizing settings. To be more specific, in Interface Builder, make sure autoresizing is clicked, then in the Size Inspector, make sure the tableview all it's superviews of the table view have red arrows filled in on the top, left, right, and also select the two internal arrows.
I am wondering if the questioner actually had the table view in a subview of the main view. I see this behavior for a table view that is one level deeper in the view hierarchy:
Main View
Subview
Table View
By default, the Main View has it's autosizing arrows set up correctly, but if you add an additional view, it does not.
In response to the question about the problem being with multiple view controllers: Note that a UIViewController is not a UIView's delegate. In fact, it looks like chain of events goes the other way - first the system sees an autorotation and tells the UIViewControllers about it. If the UIViewControllers have shouldAutoresize returning yes, then the UIViewControllers resize their main views. The resizing of the main views can automatically cause their subviews to resize if they are set correctly.
According to Apple docs, you should not have multiple view controllers controlling different parts of a view - for example a separate tableview controller for a table view that is in a subview of the main view - because it mucks with the event chain - you could see how that would be the case here. Don't know if that's helpful or not.
I just tried this, and it works as expected. You will need to provide more detail, I think. In my experience, when a view "fails" to rotate, that's because some view controller somewhere is telling it not to. Check to make sure all your view controllers are returning the right values from shouldAutorotateToInterfaceOrientation:
if your are using storyboard, your VC contains a UITableview, check if your Scene have AutoLayout unchecked.