- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到一个奇怪的错误,该错误仅在iOS 10上发生。
我有一个具有多个屏幕的应用程序,每个屏幕在navigationBar
中为viewWillAppear
上色。因此,当您进入下一个屏幕时,它将正确着色。
但是,在iOS 10上进行测试时,回到上一个屏幕时,我突然看到以下行为:
当出现上一个屏幕时,navigationBar
仍然具有上一个屏幕的颜色,然后闪烁为正确的颜色。
它看起来几乎像viewWillAppear
一样表现为viewDidAppear
。
相关代码:
ViewController:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[ViewControllerPainter paint:self withBackground:[UIColor whiteColor] andForeground:[UIColor blackColor] andIsLight:true];
}
+ (void)paint:(UIViewController *)controller withBackground:(UIColor *)backgroundColor andForeground:(UIColor *)foregroundColor andIsLight:(bool)isLight
{
controller.navigationController.navigationBar.opaque = true;
controller.navigationController.navigationBar.translucent = false;
controller.navigationController.navigationBar.tintColor = foregroundColor;
controller.navigationController.navigationBar.barTintColor = backgroundColor;
controller.navigationController.navigationBar.backgroundColor = backgroundColor;
controller.navigationController.navigationBar.barStyle = isLight ? UIBarStyleDefault : UIBarStyleBlack;
controller.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: foregroundColor};
}
最佳答案
这是根据iOS 10 SDK Release Notes更改的内容:
In iOS 10, UIKit has updated and unified background management for UINavigationBar, UITabBar, and UIToolbar. In particular, changes to background properties of these views (such as background or shadow images, or setting the bar style) may kick off a layout pass for the bar to resolve the new background appearance.
In particular, this means that attempts to change the background appearance of these bars inside of -[UIView layoutSubviews], -[UIView updateConstraints], -[UIViewController willLayoutSubviews], -[UIViewController didLayoutSubviews], - [UIViewController updateViewConstraints], or any other method that is called in response to layout may result in a layout loop.
viewWillAppear
触发了提到的布局循环,因为它是由于布局更改而被调用的:
popViewControllerAnimated
和
pushViewController
并更新我的
navigationBar
子类上的
UINavigationController
背景。看起来是这样的:
override func popViewControllerAnimated(animated: Bool) -> UIViewController? {
let poppedViewController = super.popViewControllerAnimated(animated)
// Updates the navigation bar appearance
updateAppearanceForViewController(nextViewController)
return poppedViewController
}
override func pushViewController(viewController: UIViewController, animated: Bool) {
super.pushViewController(viewController, animated: animated)
// Updates the navigation bar appearance
updateAppearanceForViewController(viewController)
}
popViewControllerAnimated
和
pushViewController
的。因此,如果您想找到另一个地方来更新
navigationBar
背景,请记住这一点。
关于ios10 - ViewWillAppear中的Navigationbar着色在iOS 10中为时已晚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39511088/
尝试从 parsCit 运行这个小 perl 程序: parsCit-client.pl e1.txt Too late for -CSD option at [filename] line 1 e1
我通常这样做: git init git add . git commit . 然后我意识到它即将添加我想要排除/忽略的 nbproject 目录。有时,我什至检查这个目录。如果我在运行 git ad
我正在处理我的代码,它的工作是,但 Action (插入 css)是 Action 的后期。 jQuery(document).ready(function() { jQuery("#cal
我是一名优秀的程序员,十分优秀!