xcode `[[[UIApplication sharedApplication] keyWindow] addSubview:` 在底部留下空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2229531/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:07:11  来源:igfitidea点击:

`[[[UIApplication sharedApplication] keyWindow] addSubview:` leaves space at bottom

iphonexcodeinterface-builderuitabbar

提问by Emil

I am trying to load in a view (with a Date Picker) on top of a Tab Bar that's loaded in as a subview in my apps delegate files.

我正在尝试在选项卡栏顶部加载一个视图(使用日期选择器),该选项卡栏作为我的应用程序委托文件中的子视图加载。

I do it like this:

我这样做:

[[[UIApplication sharedApplication] keyWindow] addSubview:viewWithPicker];

It works, but it leaves a small gap at the bottom, just big enough to show the tab bar.
How can you remove the subview again after adding it?

它有效,但它在底部留下了一个小间隙,大到足以显示标签栏。
添加子视图后如何再次删除它?

Does anyone know how to fix it? Thanks :)

有谁知道如何修理它?谢谢 :)

采纳答案by Ole Begemann

You are responsible for setting viewWithPicker's frameor centerproperty correctly so that it will appear at the correct position.

您有责任正确设置viewWithPicker'sframecenter属性,使其出现在正确的位置。

回答by willcodejavaforfood

Did you in Interface Builder configure it to leave space at the bottom for a ToolBar or otherwise set the size to anything that would make it smaller than the full size (480 x 320px)?

您是否在 Interface Builder 中将其配置为在底部为 ToolBar 留出空间,或者将大小设置为任何会使其小于完整大小 (480 x 320px) 的大小?

If you are adding it as a subview to a ViewController that is using a ToolBar you might want to check thisquestion for more information.

如果您将它作为子视图添加到使用 ToolBar 的 ViewController,您可能需要检查问题以获取更多信息。

回答by Jasarien

The key window takes up the full screen size (320 x 480), however, the status bar is drawn above the key window at all times.

按键窗口占据全屏尺寸(320 x 480),但状态栏始终绘制在按键窗口上方。

When you add a subview to the key window without settings its frame or centre manually, its origin will be placed at (0,0), which the status bar is drawn on top.

当您将子视图添加到关键窗口而不手动设置其框架或中心时,其原点将放置在(0,0)处,状态栏绘制在其顶部。

The space you're seeing at the bottom of the view is because your view likely has its height set to 460, which happens if the view was created in Interface Builder and has the "simulated interface elements" set to show the status bar.

您在视图底部看到的空间是因为您的视图可能将其高度设置为 460,如果视图是在 Interface Builder 中创建的并且将“模拟界面元素”设置为显示状态栏,则会发生这种情况。

You'll need to change the subview's yvalue to position it below the status bar. 20 is usually a good value to use, since that's the status bar's height. However, the status bar height may change in future versions of the iPhone OS, so hardcoding values like that is a bad idea.

您需要更改子视图的y值以将其放置在状态栏下方。20 通常是一个很好的使用值,因为这是状态栏的高度。但是,状态栏高度在 iPhone 操作系统的未来版本中可能会发生变化,因此硬编码这样的值是一个坏主意。

回答by Emil

I fixed it!

我修好了它!

As simple as setting the overlay view to 480px height.

就像将覆盖视图设置为 480 像素高度一样简单。