gpt4 book ai didi

ios - UINavigationController barstyle 属性改变布局

转载 作者:行者123 更新时间:2023-12-01 19:26:24 24 4
gpt4 key购买 nike

我有一个显示导航 Controller 的模态视图 Controller 。导航 Controller 反过来有一个常规的 UIViewController 作为它的 Root View Controller 。上面提到的 UIViewController 唯一的 UI 元素是 UISwitch。

现在问题来了:当我更改导航 Controller 的 barStyle 属性时,UIViewController 内的 UISwitch 的布局发生了变化。这就是我所说的:

如果我不设置 barStyle 属性,这就是我得到的:

http://img535.imageshack.us/img535/2281/plaini.png

UISwitch 现在处于“预期”的位置。

现在,如果我设置 barStyle 属性,

navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

请注意,UISwitch 位于导航栏后面:

http://img853.imageshack.us/img853/2377/blackya.png

这是 UIViewController 中 UISwitch 的代码:
- (void)viewDidLoad
{
UISwitch* mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
[self.view addSubview:mySwitch];
[mySwitch release];
}

有人可以帮助我了解发生了什么吗?

最佳答案

当您使用 UIBarStyleBlackTranslucent (实际上已弃用)属性时,框架会发生变化,因为它假定您希望您的 View 位于下方

Apple Documentation说要使用以下内容,因为 UIBarStyleBlackTranslucent 已弃用:

navController.navigationBar.barStyle = UIBarStyleBlack;
navController.navigationBar.translucent = YES;

您可以尝试将 View 移回正确的位置或尝试使用以下方法:
navController.navigationBar.tintColor = [UIColor blackColor];
navController.navigationBar.translucent = YES;

关于ios - UINavigationController barstyle 属性改变布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7287672/

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