Nih*_*hat 87 objective-c uinavigationbar uinavigationcontroller segue
当我在主 - 细节导航控制器中的父控制器和子控制器之间来回导航时,我看到顶部导航栏右侧的阴影.它在我升级到Xcode 5.1之后开始.感觉粗糙,分散注意力.我怎么能摆脱它?
non*_*ive 138
self.navigationController.view.backgroundColor = [UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)
我通过设置导航控制器视图的背景颜色解决了这个问题.
Nih*_*hat 50
self.navigationController.navigationBar.translucent = NO;
Run Code Online (Sandbox Code Playgroud)
固定它
man*_*mal 36
nonamelive的答案是完美的.要在Interface Builder 和STILL KEEP TRANSLUCENCY中实现相同的功能,请选择导航控制器并设置用户定义的运行时属性view.backgroundColor,如屏幕截图所示(在Identity Inspector中).对显示此问题的所有导航控制器重复此操作.
看起来整个问题的出现是因为当动画开始时CoreGraphics对它进行快照时,UINavigationController的黑色(或实际上没有颜色)正在泄漏.因此,将其设置为白色将阻止这种情况.
这似乎是iOS 7.1中引入的错误.在我的情况下,它是由直接放置在导航栏下方的UIToolbar引起的.暗影也出现在半透明标签栏中.
阴影似乎是由UIToolbar的背景视图引起的.我现在在视图控制器中使用此变通方法,工具栏在过渡期间隐藏工具栏的背景视图:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UIView *toolbarBackgroundView = [self.toolbar findViewRecursively:^BOOL(UIView *subview, BOOL *stop) {
BOOL isToolbarBackgroundView = ([subview isKindOfClass:[UIImageView class]]
&& [NSStringFromClass(subview.class) isEqualToString:@"_UIToolbarBackground"]);
if (isToolbarBackgroundView) {
*stop = YES;
}
return (! isToolbarBackgroundView);
}];
if (toolbarBackgroundView) {
// fade toolbar background view back in
[UIView animateWithDuration:0.1f animations:^{
toolbarBackgroundView.alpha = 1.0f;
}];
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
UIView *toolbarBackgroundView = [self.toolbar findViewRecursively:^BOOL(UIView *subview, BOOL *stop) {
BOOL isToolbarBackgroundView = ([subview isKindOfClass:[UIImageView class]]
&& [NSStringFromClass(subview.class) isEqualToString:@"_UIToolbarBackground"]);
if (isToolbarBackgroundView) {
*stop = YES;
}
return (! isToolbarBackgroundView);
}];
if (toolbarBackgroundView) {
// hide toolbar background view
toolbarBackgroundView.alpha = 0.0f;
}
}
Run Code Online (Sandbox Code Playgroud)
这是代码 [UIView findViewRecursively:]
@interface UIView (FindSubview)
- (UIView*)findViewRecursively:(BOOL(^)(UIView* subview, BOOL* stop))recurse;
@end
@implementation UIView (FindSubview)
- (UIView*)findViewRecursively:(BOOL(^)(UIView* subview, BOOL* stop))recurse {
for (UIView* subview in self.subviews) {
BOOL stop = NO;
if (recurse(subview, &stop)) {
UIView* view = [subview findViewRecursively:recurse];
if (view) return view;
} else if (stop) {
return subview;
}
}
return nil;
}
@end
Run Code Online (Sandbox Code Playgroud)
我提交了这个雷达:http://openradar.appspot.com/16418845
这在Swift 中对我有用
在AppDelegate对didFinishLaunchingWithOptions方法,我设置:
UIApplication.shared.windows.first?.backgroundColor = .white
Run Code Online (Sandbox Code Playgroud)
这对我来说适用于浅色和深色主题的iOS 13,也适用于较旧的 iOS 版本。
将以下代码添加到 AppDelegate 方法中application(didFinishLaunchingWithOptions):
if #available(iOS 13.0, *) {
window?.backgroundColor = UIColor.systemBackground
} else {
window?.backgroundColor = UIColor.white
}
Run Code Online (Sandbox Code Playgroud)