REALLY strange app color behavior? - ios

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()

Related

UINavigationController strange pop animation

I have a strange animation when I pop a ViewController on my NavigationController. Short video to illustrate: https://youtu.be/IMbIS7evLrs
The view controller structure is:
UITabBarController -> UINavigationControllers -> UIViewControllers
I push the new VC using this line in my UIViewController:
[self.navigationController pushViewController:tripVC animated:YES];
Where tripVC is a newly created UIViewController.
Then the pop happens when the NavigationController Back button is clicked. I've also tried calling the pop programmatically using
[self.navigationController popViewControllerAnimated:YES];
from within tripVC and get the same strange animation.
What's particularly odd is I've used this structure / approach on other apps and haven't had this problem. Am wondering if there's some strange segue code in my app / am missing some animation code?
It seems that the background image in the second VC is wider than the device screen. As this scene pushes in/out the normally hidden edge of the image is revealed briefly.
Yes, for my case #Paulw11 is right. Enable clipsToBound to your root view.
If you haven't given background color of self.view then also it may occur.
This is the second reason for strange animation for navigation.

can't set to "UIBarPositionTopAttached" on navigationBar

I made UIViewController which have navigationController as parent (connected in storyboard),
and I want to apply picture of navigationBar for statusBar background.
but it seems that statusBar can't be state like "Translucent",
I tried to set
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController.navigationBar setBackgroundImage:[UIImage
imageNamed:#"barTop.png"] forBarPosition:UIBarPositionTopAttached
barMetrics:UIBarMetricsDefault];
[self setNeedsStatusBarAppearanceUpdate];
....
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
in UIViewController.
But backgrounds of navigation and status Bar have been separated.
I try both to make plist file as "View controller-based status bar appearance" YES and NO. but still I can't configure statusBar from viewController.
I couldn't find same problem in this bulletin board .
does anyone knows solution??or how to debug?
thank you for reading.
(9/3 added: I want to make backgrounds together for navigationBar and statusBar.
And under the simple condition like that there are one navigationController and one ViewController, both bars can make their backgrounds together (default).
Now I met the something wrong when I make tabBarController indicate to multiple navigationController by storyboard.)
According to Apple for Status bar, status bar is Transparent.(I think* always, not sure). Here is the link. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Bars.html
Although I found the solution this a few month ago,it took a time to align the point.
checking my viewController structure causing problem , It found Black of the statusBar is self.window.backgroundColor.
so this mean status bar and navigationController was originally succeeded to be transparent, my viewController is aligned (20, 0). this was root of this problem.
and I found that this problem derived from applying contentInsets setting.
this setting affects to even view.subviews[0] too.
this happen when under some condition
•uiViewController’s view displayed via UInavigationController
•edgesForExtendedLayout is active
•view’s first element is kind of UIScrollView or these subclass
(from japanese bulletin board)
to solute this , I made originally navigationController on the storyBoard to separate from these inset setting then I explicitly set its origin to (0,0)
and I set automaticallyAdjustsScrollViewInsets = NO on my viewController.
after that, finally I could set viewController’s origin to (0,0), and I made navigationBar’s back being statusBar’s back.
below link contains so much useful information.
iOS 7 status bar back to iOS 6 default style in iPhone app?

UINavigationController transparent for UITableView underneath

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.

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?

Why Does presentModalViewController:animated: Turn The Background Black?

I am using presentModalViewController:animated: and while functionally it works correctly visually it has an artifact I want to remove. When the modally presented viewController appears its parent viewController is completely hidden with the background turning black. This is not what I want. My child viewController's view is translucent and I want to reveal the parent viewControllers view behind it. The effect I want is a piece of tracing paper sliding over the background.
I assumed presentModalViewController:animated: supported this. Is that not the case?
Thanks,
Doug
NavigationController and the View Controllers are designed in such a way that only one view controller may show at a time. When a new view controller is pushed/presented the previous view controller will be hidden by the system. So when you reduce the modal view's alpha you will possibly see the window's backgroundColor (the black color you see now).
If you want a translucent view to slide-in over the main view, you can add the view as the subView of main view and animate it using UIView Animations.
This may get you what you want:
presentingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
presentingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
doesn't work after ios7,you can fix it by after
presentingViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
presentingViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
then both:
[appViews.rootViewController presentViewController:presentingViewController animated:YES completion:nil];

Resources