UINavigationController barstyle 属性更改布局
我有一个显示导航控制器的模式视图控制器。导航控制器又具有常规 UIViewController 作为其根视图控制器。上述 UIViewController 拥有的唯一 UI 元素是 UISwitch。
现在的问题是:当我更改导航控制器的 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];
}
有人可以帮助我吗明白发生了什么事吗?
I have a modal view controller which displays a navigation controller. The navigation controller in-turn has a regular UIViewController as its root view controller. The only UI element that the above-mentioned UIViewController has is a UISwitch.
Now here's the problem: When I change the barStyle property of the navigation controller, the layout of the UISwitch inside the UIViewController changes. Here's what I am talking about:
If I don't set the barStyle property, here's what I get:
http://img535.imageshack.us/img535/2281/plaini.png
The UISwitch is now in its 'exepected' place.
Now if I set the barStyle property,
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
Notice that the UISwitch is behind the navigation bar:
http://img853.imageshack.us/img853/2377/blackya.png
Here's the code for the UISwitch in the UIViewController:
- (void)viewDidLoad
{
UISwitch* mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
[self.view addSubview:mySwitch];
[mySwitch release];
}
Can someone help me understand what's happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 UIBarStyleBlackTranslucent (实际上已弃用)属性时,框架会发生变化,因为它假设您希望视图位于
Apple 文档 表示要使用由于 UIBarStyleBlackTranslucent 已被弃用,因此以下内容:
您可以尝试将视图移回正确的位置或尝试使用以下内容:
The Frame shifts when you use the UIBarStyleBlackTranslucent (which is actually deprecated) property because it assumes you want your view to be underneath
The Apple Documentation says to use the following since UIBarStyleBlackTranslucent is deprecated:
You could try shifting your view back in the correct place or try using the following: