UINavigationController barstyle属性更改布局 [英] UINavigationController barstyle property changes layout
问题描述
我有一个显示导航控制器的模态视图控制器.导航控制器又将常规UIViewController作为其根视图控制器.上述UIViewController唯一具有的UI元素是UISwitch.
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.
现在是问题所在:当我更改导航控制器的barStyle属性时,UIViewController内的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:
如果我没有设置barStyle属性,这就是我得到的:
If I don't set the barStyle property, here's what I get:
http://img535.imageshack.us/img535/2281/plaini.png
UISwitch现在处于期望的"位置.
The UISwitch is now in its 'exepected' place.
现在,如果我设置了barStyle属性,
Now if I set the barStyle property,
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
请注意,UISwitch位于导航栏的后面:
Notice that the UISwitch is behind the navigation bar:
http://img853.imageshack.us/img853/2377/blackya.png
这是UIViewController中的UISwitch的代码:
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?
推荐答案
使用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:
navController.navigationBar.barStyle = UIBarStyleBlack;
navController.navigationBar.translucent = YES;
您可以尝试将视图移回正确的位置或尝试使用以下方法:
You could try shifting your view back in the correct place or try using the following:
navController.navigationBar.tintColor = [UIColor blackColor];
navController.navigationBar.translucent = YES;
这篇关于UINavigationController barstyle属性更改布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!