REALLY strange app color behavior?

ⅰ亾dé卋堺 提交于 2019-12-03 05:53:30

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.

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()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!