我的状态栏后面有20px的问题,特别是我不能放任何东西。
当我创建UI时,我使用了故事板方法并将状态栏样式设置为半透明黑色。但是当Xcode中的布局时,我的视图的高度固定为460px(灰显)。
请帮忙。
得到朋友的回答,一旦他在这里发布,就会将他的解决方案标记为正确答案。现在这里是解决方案:
答案 0 :(得分:7)
这是没有单行代码的解决方案。
请参阅顶部帖子中每个步骤的屏幕截图链接。
答案 1 :(得分:2)
好的,我被告知可能,我尝试在主视图顶部放置一个视图,并将其y坐标设置为-20。然后我向西到Info.plist并将Status bar style
设置为Transparent black style (alpha of 0.5)
。我放置的视图在状态栏下方可见。
这只发生在运行时;在Interface Buider中,模拟的半透明状态栏是灰色但不透明。
修改:如果您想将视图控制器的主视图移动到此空间,则可以在viewWillAppear
期间进行。 (如果你试图在viewDidLoad
期间移动它,它会在之后被移回。)
- (void)viewWillAppear:(BOOL)animated;
{
[super viewWillAppear:animated];
// Move the main view upwards if it isn't already there.
CGRect frame = [[self view] frame];
frame.size.height += frame.origin.y;
frame.origin.y = 0;
[[self view] setFrame:frame];
}
然而,它会在轮换后被移回,而我对旋转做出反应的尝试最终破坏了单元格布局,如果我这样做了UITableView
。
这是Swift版本。似乎工作。获取这些App Store屏幕截图的好方法(除了使info.plist更改之外。
覆盖func viewWillAppear(动画:Bool){
super.viewWillAppear(animated)
// Move the main view upwards if it isn't already there.
var frame: CGRect = self.view.frame
frame.size.height += frame.origin.y
frame.origin.y = 0
self.view.frame = frame
}
答案 2 :(得分:1)
只需在界面构建器中创建负Y(-20)坐标。
答案 3 :(得分:-1)
尝试在Interface Builder的“属性”检查器的“模拟指标”部分中更改“状态栏”的值。如果将其设置为“推断”,Xcode将不对视图控制器进行任何假设,允许您将视图的大小设置为您想要的任何大小(即使是没有任何意义的大小)。查看this post about the status bar,了解有关将其隐藏在应用中的信息。