gpt4 book ai didi

ios - 导航栏外观在第一次设置后不会改变

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:20:08 24 4
gpt4 key购买 nike

当应用程序激活时,我为导航栏的标题设置了一定的垂直偏移量:

[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-3.0f forBarMetrics:UIBarMetricsDefault];

然后,在导航层次结构的后面,我需要设置一个不同的垂直偏移量,所以我调用:

[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-0.5f forBarMetrics:UIBarMetricsDefault];

但我发现当我在应用程序处于事件状态的情况下导航时,新的垂直偏移并未应用。但是,如果应用程序变为非事件状态然后再次事件,则会应用它。当应用程序保持在前台时,如何更改此偏移量?

谢谢!

最佳答案

来自 https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAppearance_Protocol/index.html

iOS applies appearance changes when a view enters a window, it doesn’t change the appearance of a view that’s already in a window. To change the appearance of a view that’s currently in a window, remove the view from the view hierarchy and then put it back.

所以基本上你需要做一些 HACK 来删除 View ,然后立即将其添加回来,就像这样......

UIView *currentview = ((AppDelegate*)[UIApplication sharedApplication].delegate).window.rootViewController.view;
UIView *superview = currentview.superview;
[currentview removeFromSuperview];
[superview addSubview:currentview];

对于 Swift...

if let currentview = (UIApplication.sharedApplication().delegate as? AppDelegate)?.window?.rootViewController?.view {
if let superview = currentview.superview {
currentview.removeFromSuperview()
superview.addSubview(currentview)
}
}

关于ios - 导航栏外观在第一次设置后不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19764993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com