UINavigationController transparent for UITableView underneath - ios

I have a UINavigationController handling then navigation in my app. I would like the navigation bar to show the contents of the UITableView as I scroll up.
I can't seem to get it to be transparent. I have it set to translucent
self.navigationController.navigationBar.translucent = YES;
But still nothing. I'd like to add color, but I'll worry about that later. I've tried creating a subclass of UINavigationController and specify
self.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = NO;
But again, no luck. This is what my interface builder looks like...
And this is what it looks like when I scroll the text up under the nav bar. Any suggestions?

Alright, I figured out a (seemingly simple) solution.
If you're using a UINavigationController to add a UINavigationBar to each of your views, this will work for making a transparent navigation bar.
Select the Navigation bar in your UINavigationController
Then, in the inspector bar (on the right), select "Clear Color". Tada! I'm a bit embarrassed I didn't try this sooner. Hopefully this will save someone else lots of time.

Try using a UITableViewController embedded in a UINavigationController, instead of a UIViewController. It'll adjust the insets for the iOS7 live blur automatically, so that the list content will show up under the Toolbar/NavigationBar on scroll.
I can't really make it out from your screenshot, but you can disable 'Hide Toolbar' in the parent NavigationController. You then don't have to add it separatly.

Related

REALLY strange app color behavior?

On appDidFinishLaunchingWithOptions, I tint my entire app red with the following code.
self.window.tintColor = [UIColor otfRedColor];
This works perfectly, and when my app loads, all the navigation bar items are red. A is my root view controller.
I have 3 view controllers, a, b, and c. A pulls up a modal presentation view sheet of b which pulls up a full modal view of c. When C is pulled up, the bar button items on navigation bar are all tinted gray, this shouldn't be happening because I didn't alter any tint or color in any way after the app delegate tinted the window. I then use
[self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
to dismiss VC c and b, but now my ENTIRE app is tinted gray. I haven't used any tint code at all since the app delegate, why does this happen? When I go from A to B again, that navigation bar items are still red???
Code to pull up view controller B from A:
AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:#"addAthlete"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
addAthlete.delegate = self;
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
Code to pull up C from B:
MedicalReleaseVC *medRelease = [self.storyboard instantiateViewControllerWithIdentifier:#"showMedRel"];
medRelease.delegate = self;
[self presentViewController:medRelease animated:YES completion:nil];
Does anyone know why this happens, or have an idea? I have tried tinting the third view controller as red 3 separate ways and it still remained gray, then when everything is dismissed my entire app is gray. Please help!!
EDIT:
If it helps, the way I solved this problem was by setting the following in my appdelegate.m
self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
I think this is a bug in iOS7's handling of tintAdjustmentMode when opening and closing sheets and popovers. I've seen this bug happen in Apple's native mail app, where the bar button items become gray, or conversely, they no longer turn to gray once a popover shows up.
To debug this further, I suggest subclassing one of your views (or the window directly) and implementing tintColorDidChange. Log the value of tintAdjustmentMode there. I fear this is what is causing your gray tint issues.
One solution would be to force UIViewTintAdjustmentModeNormal but this would have the effect of no dimming when opening a popover or a sheet.
I had to put
[[[UIApplication sharedApplication] keyWindow] setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];
in my viewDidLoad to solve this issue. But as mentioned in other answers, it does have the adverse effect of not dimming the bar button items when a popup is up.
I set this at the appearance proxy level.
UINavigationBar.appearance().tintAdjustmentMode = .normal
Just put
self.view.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
in your viewDidLoad and your colors are back to normal.
There is definitely a bug. I noticed that when the popover does dim the window when it appears but after I change the keyWindow.tintAdjustmentMode manually (for custom views & modal view controllers), the popover will stop dimming even though I set the keyWindow.tintAdjustmentMode back to automatic.
When a popover is shown, the main view's TintAdjustmentMode is set to Dimmed. This should be reversed when the popover is closed, but when you navigate to a new screen from the popover, it doesn't happen for some reason.
I fixed this in the UIViewController being displayed as the popover - override the ViewWillDisappear method and set the TintAdjustmentMode on the main view controller's view back to Normal. (In Xamarin, I used UIApplication.SharedApplication.KeyWindow.RootViewController.View.TintAdjustmentMode = UIViewTintAdjustmentMode.Normal with a few checks for nulls along the way.)
Another solution is to NOT set the window tintColor and instead use appearance proxies where appropriate and set tintColor programmatically (or in Interface Builder) everywhere else. This appears to be safer than setting the global window tintColor, which elicits strange behavior especially after modals, system alerts, and action sheets dismiss.
Remove this:
self.window?.tintColor = UIColor.redColor()
Add these:
UINavigationBar.appearance().barTintColor = UIColor.redColor()
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UISegmentedControl.appearance().tintColor = UIColor.orangeColor()

how to present a view controller on iOS7 without the status bar overlapping

I'm seeing when I migrated my app to iOS 7, the nav bar is appearing under the status bar when presenting a view controller. I think a lot of people have run into this same issue. Here's a screenshot of what I'm seeing:
Requirements:
The new view must appear "modally", i.e. I need presentViewController.
Display some sort of nav bar or toolbar, with the status bar taking on the background color of the nav bar ala iOS 7 style.
It must work on iOS 6.
I'm using a xib to handle layout, with autolayout enabled.
Options:
A. Shift your view's frame down by a bit.
Ugh, are we back to the pre-iOS 5 days and mucking with frames? Also it's generally not a good idea mixing with autolayout.
B. Add a little gap up top below your nav bar.
One disadvantage of options A and B is the status bar won't blend into your nav:
C. Programatically add constraints.
The main disadvantage is you'll have to muck with constraints and calculating the nav and status bar heights. Yuck.
D. Stretch the navigation bar / toolbar's height to include the area of the status bar.
Looks good on iOS 7, but breaks on iOS 6. You'll need to programatically update the height of the nav bar, and also make sure the rest of your view updates appropriately. Messy.
E. Mess with iOS6/7 deltas in IB.
Multiple disadvantages: You'll be hardcoding the ios6/7 deltas. Also doesn't work with autolayout.
F. Use a nested UINavigationController.
This is the workaround I selected. See answer below.
The easiest workaround I've found is to wrap the view controller you want to present inside a navigation controller, and then present that navigation controller.
MyViewController *vc = [MyViewController new];
UINavigationController *nav = [[UINavigationController alloc]
initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:NULL];
Advantages:
No mucking with frames needed.
Same code works on iOS 6 an iOS 7.
Less ugly than the other workarounds.
Disadvantages:
You'll probably want to leave your XIB empty of navigation bars or toolbars, and programatically add UIBarButtonItems to the navigation bar. Fortunately this is pretty easy.
You need to add a Vertical Constraint from your top most view to Top Layout Guide as described in the following article by Apple.
https://developer.apple.com/library/ios/qa/qa1797/_index.html
Next code worked for me. Just put it to the controller which is presenting the new controller.
#pragma mark hidden status bar
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
open you xib file and select the viewcontroller. in the inspector tab select the attributes and select in TopBar "Opaque Navigation Bar".
this solved the problem for me.

UINavigationBar disappears before pushing view animation and appears after it. Whats wrong?

I have three views and a navigation bar with my background image. When I push second view, everything goes like it should: navigation bar stays on its place with background image, just caption and buttons swipe away to the left and get replaced by "back" button and new caption for the second view. But when i push a third view, the transition goes like this: just right before animation, navigation bar disappears totally, leaving app's window background color on its place, and then, new navigation bar swipes from the right with all the ui element. and the same goes when i pop third view (push "back button").
Any ideas, why it is happening? It was normal before, but at the some point I noticed it start working like this.
Just out of curiosity, do you have a UISearchBar in the view you are pushing onto the stack? I was having the exact same issue as you described, it turned out it was caused by the UISearchBar and UISearchDisplayController.
When creating the UISearchBar and UISearchDisplayController I was calling
self.searchBar = [[[UISearchBar alloc] init] autorelease];//init the UISearchBarView
then somewhere further along in the code I was calling
[self.searchDisplayController setActive:YES animated:NO];
[self.searchDisplayController setActive:NO animated:NO];
The above two calls to "[setActive: animated:]" would layout the UISearchBar correctly for some unknown reason. I have seen this solution in many places on the interwebs. But a side effect would be that the navbar turns white when pushing a new view that had a search bar.
To fix everything I instead initialized the UISearchBar by calling:
self.searchBar = [[[UISearchBar alloc] initWithFrame:frame] autorelease];
and then I deleted the two calls to "[setActive: animated:]"
This change resulted in a properly laid out search bar without the disappearing navbar.
Hope somebody will find this post useful!
You aren't pushing a UINavigationController on top of your main navigationController?

How to hide the UITabBar and show UIToolBar?

I read several answers to this question but couldn't figure out how to do it. I'm using Xcode 4.2 with ARC and no storyboards.
I'm developing an app based on the TabBar application template and extended it to contain 4 UITabBars. I'm not using UINavigationController but instead using UINavigationBar next to the status bar. When the app is loaded with the first tab shown, I have a button on the UINavigationBar and when I press it, I want to hide the UITabBar and instead show the UIToolBar at the same location where the UITabBar was located.
I tried to hide and show using the hidden property (hiding the UITabBar and showing UIToolBar). What happens is the UITabBar is hidden but the UIToolBar is shown above the location where the UITabBar was shown before. This looks ugly and I want it to be shown at the very bottom of the screen.
I think I can't use hidesBottomBarWhenPushed as I don't use a UINavigationController but instead using Navigation bar directly.
Also, I want to revert back to showing the UITabBar and hide the UIToolBar when pressing the same button on the UINavigationBar.
I am not sure if my idea would work for your scenario. Here it is...
but before, just let me tell you that hiding UITabBar, unlike hiding UINavigationBar is not animated. So to me, hiding tabBar is not a user-friendly approach, unless you create your own subclass of UITabBarController that animates hiding the UITabBar.
You can use presentModalViewController:animated and dismissModalViewControllerAnimated: methods. The viewController that is being shown modally can have a UINavigationBar, it pops out from the bottom of the screen and covers the UITabBar with animation.
Hope that helps.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

Add a toolbar to a tableView

I'm using the XCode 4.3 "Master/Detail" template for the iPhone. At the ROOT level, this is a UIToolbarController. I want navigation and toolbars. The navigation is easy--the template already uses the self.navigationItem.leftBarButtonItem (and right) to add buttons, but I can't find a way to add useful toolbar items. I can add a toolbar (see below), but this gets added to the scroll view of the tableview, so scrolls up and down with the table contents--not very useful. The tableView.view has no superview which is where you'd think a tool bar should go. It has no window either! (all these properties are null).
That top navbar must belong to some view which is not scrolled, but what?!! Setting the toolbarHidden property of self.navigationController has no effect (setting the navigationBarHidden to YES does not hide the nav bar either).
Obviously something I don't understand here...
// this toolbar scrolls with the tableview contents!
INavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:self];
nvc.toolbarHidden = NO;
[self.view addSubview:nvc.view];
Just highlight the navigation controller and then look at the attributes. check "Shows Toolbar" to unhide the toolbar that is already there.

Resources