为什么我的应用程序的导航栏上有一个 20 像素高的黑色覆盖层?
再一次,我几乎完全确定这是我正在做的一件愚蠢的事情,但我已经用我的头撞了几个小时了。我毫无进展。
我正在尝试重构我的应用程序的视图层次结构。我需要能够全局检测用户界面方向的变化,以便在应用程序下载内容时正确旋转显示的“正在加载”视图。 (设备方向变化似乎在不同时间触发,导致需要响应这些事件的视图偶尔旋转)。
该应用程序之前将 UINavigationController 的视图添加到主窗口。我修改了层次结构以将 UIViewController 子类的视图添加到主窗口,并将 UINavigationController 的视图添加到子类的视图中。 UIViewController 子类管理显示和显示。 “正在加载”子视图的旋转,我希望应用程序的其余部分能够继续正常运行,因为在层次结构中插入一个额外的空视图并不觉得我改变了太多。
我最初的问题是 UINavigationController 的定位 - 它太低了 20 像素,导致状态栏和导航栏之间出现间隙,并切断了选项卡栏底部的 20 像素。我可以通过将 UINavigationController 的视图的frame属性设置为UIViewController的视图的bounds属性来调整这一点,从而纠正了位置。
然而,现在我的导航栏顶部有一个 20 像素高的黑色“覆盖层”。如果让我猜的话,我会说它是黑色,不透明度为 50%。此栏上的触摸事件不起作用(例如,如果我尝试通过覆盖层点击“后退”按钮,则不会发生任何情况)。我没有忽略高度与状态栏的高度相等的事实,但我完全不知道是什么原因造成的。
我讨厌这种愚蠢的感觉,所以如果有人对这个问题有任何见解,你真的会让我的天。提前致谢!
Once again, I'm almost entirely sure this is something dumb that I'm doing, but I've been banging my head against this one for hours & am getting nowhere.
I'm trying to restructure the view hierarchy of my app. I need to be able to detect user interface orientation changes globally in order to correctly rotate a "Loading" view displayed when the app is downloading content. (device orientation changes seem to fire at different times, causing the view that needs to respond to these events to rotate sporadically).
The app previously added a UINavigationController's view to the main window. I modified the hierarchy to add the view of a UIViewController subclass to the main window, and added the view of the UINavigationController to the subclass's view. The UIViewController subclass manages the display & rotation of the "Loading" subview, and I was expecting the rest of the app to continue behaving normally, as inserting one extra empty view into the hierarchy didn't feel like I was changing too much.
My initial problem was the positioning of the UINavigationController - it was 20 pixels too low, resulting in a gap between the status bar and the navigation bar, and cutting off the bottom 20 pixels of the tab bar. I was able to adjust this by setting the frame property of the UINavigationController's view to the bounds property of the UIViewController's view, which corrected the position.
However, now I'm stuck with a 20-pixel-high dark "overlay" on top of my navigation bar. If I were to guess, I'd say it was black with 50% opacity. Touch events on this bar don't work (e.g. if I try to tap the "Back" button through the overlay, nothing happens). The fact that the height is equal to that of the status bar hasn't escaped me, but I'm at a total loss as to what could be causing it.
I hate feeling this stupid, so if anyone has any insight into this problem, you'd really make my day. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,从您的帖子中可以看出一些内容。
这让我相信它与您的新问题有关。
这听起来像是它加载到的视图偏移了 20 像素,当您将其设置为边界时,它会在 Windows 视图空间上重新定位它。
这是一件大事。如果触摸事件没有发送到视图,那么这意味着操作系统看不到您按下的视图(或者更确切地说是您想要的视图),因此该视图不会收到消息做某事。
根据您所说的,我相信您的问题出在您刚刚添加的基本视图控制器上。尝试重新制作框架,使其符合您想要的位置。然后取出您输入的用于设置导航控制器框架的代码。导航控制器也应该适合您添加的视图,一旦您有了需要的主视图(显然高 20 像素),那么一切都应该可以工作。
OK, a few things pop out from your post.
This makes me believe it is related to your new problem.
This sounds like the view it was loaded onto was offset 20 pixels, and when you set it to the bounds, it repositioned it on the windows view space.
This is the big thing. If touch events aren't being sent to the view, then what that means is that the OS doesn't see a view where you are pressing (or rather the view you want it to), so that view doesn't get the message to do something.
From what you have said, I believe your problem is with your base view controller that you just added. Try redoing the frame on, making it conform to where you want. Then take out the code you put in to set the navigation controllers frame. The navigation controller should fit to the view you added too, and once you have that main view where it needs to be (20 pixels higher apparently), then everything should work.