xcode iOS - 如何在带有半透明黑色状态栏的故事板中回收前 20 像素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10075597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS - How to reclaim the top 20px in storyboard w/ translucent black status bar
提问by Ivan Karpan
I have a problem with top 20px behind status bar, specifically I cannot put anything there.
我在状态栏后面的顶部 20px 有问题,特别是我不能在那里放任何东西。
When I created the UI I used the storyboard approach and set status bar style to translucent black. But when do the layout in Xcode my views' height is fixed to 460px (grayed out).
当我创建 UI 时,我使用了故事板方法并将状态栏样式设置为半透明黑色。但是当在 Xcode 中布局时,我的视图高度固定为 460px(变灰)。
Please help.
请帮忙。
Got an answer from a friend, will mark his solution as right answer as soon as he posts it here. For now here is the solution:
从朋友那里得到了答案,一旦他在这里发布,就会将他的解决方案标记为正确答案。现在这里是解决方案:
- In Interface Builder set up the view controller as wanting full screen and of freeform size: http://cl.ly/0x1p1u3q3B1y3b3C3U2n
- Then in the view's size settings set its height to 480px: http://cl.ly/1p1b0e060p1Y37393D08
- Ensure status bar style is translucent black in the Info.plist: http://cl.ly/153Y391S1b0G3J3z3Y1O
- Get satisfactory result: http://cl.ly/0Q1M390i3A3h2F3u2T19
- 在 Interface Builder 中,将视图控制器设置为想要全屏和自由尺寸:http: //cl.ly/0x1p1u3q3B1y3b3C3U2n
- 然后在视图的大小设置中将其高度设置为 480 像素:http://cl.ly/1p1b0e060p1Y37393D08
- 确保 Info.plist 中的状态栏样式为半透明黑色:http: //cl.ly/153Y391S1b0G3J3z3Y1O
- 得到满意的结果:http: //cl.ly/0Q1M390i3A3h2F3u2T19
回答by Eugene Belyakov
Here's solution without single line of code.
这是没有单行代码的解决方案。
- In Interface Builder set up the view controller as wanting full screen and of freeform size.
- In the view's size settings set its height to 480px
- Ensure status bar style is translucent black in the Info.plist.
- Launch and observe
- 在 Interface Builder 中,将视图控制器设置为想要全屏和自由尺寸。
- 在视图的大小设置中将其高度设置为 480px
- 确保 Info.plist 中的状态栏样式为半透明黑色。
- 启动并观察
See the links for screenshots of each step in the top post.
请参阅顶部帖子中每个步骤的屏幕截图链接。
回答by Dondragmer
Okay, having been told it's possible, I tried placing a view on top of the main view and setting its y coordinate to -20. Then I west to Info.plist and set Status bar style
to Transparent black style (alpha of 0.5)
. The view I placed was visible beneath the status bar.
好的,被告知这是可能的,我尝试在主视图的顶部放置一个视图并将其 y 坐标设置为 -20。然后我向西进入 Info.plist 并设置Status bar style
为Transparent black style (alpha of 0.5)
. 我放置的视图在状态栏下方可见。
This only happened at run time; in Interface Buider the simulated translucent status bar is gray but opaque.
这只发生在运行时;在 Interface Buider 中,模拟的半透明状态栏是灰色但不透明的。
Edit: If you want to move your view controller's main view into this space, it is possible during viewWillAppear
. (If you try to move it during viewDidLoad
, it gets moved back afterwards.)
编辑:如果要将视图控制器的主视图移动到此空间中,则可以在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];
}
However, it gets moved back after rotation, and my attempts to respond to rotation ended up breaking the cell layout if I did this to a UITableView
.
但是,它在旋转后被移回,如果我对UITableView
.
Here is the Swift version. Seems to work. Good solution for taking those App Store screen shots (well in addition to making the info.plist changes.
这是 Swift 版本。似乎工作。拍摄那些 App Store 屏幕截图的好解决方案(除了更改 info.plist 之外。
override func viewWillAppear(animated: Bool) {
覆盖 func viewWillAppear(动画:布尔){
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
}
回答by invoodoo
Just make negative Y (-20) coordinate in interface builder.
只需在界面构建器中制作负 Y (-20) 坐标即可。
回答by samson
Try changing the value for "Status Bar" in the "Simulated Metrics" section of the Attributes inspector in Interface Builder. If you set it to "Inferred", Xcode will make no assumptions about the view controller, allowing you to set the size of the view to ANY size you want (even sizes that don't make any sense). Check out this post about the status barfor info on hiding it in your app.
尝试更改 Interface Builder 中属性检查器的“Simulated Metrics”部分中“Status Bar”的值。如果您将其设置为“Inferred”,Xcode 将不对视图控制器做任何假设,允许您将视图的大小设置为您想要的任何大小(甚至没有任何意义的大小)。查看有关状态栏的帖子,了解有关将其隐藏在您的应用程序中的信息。