子视图显示下面的主视图
我的应用程序中有这个奇怪的错误。我正在制作一个子视图并将其绘制在主视图的顶部。为了摆脱它,我就把它隐藏起来。问题是这样的:我可以看到下面的部分视图从底部窥视,形成一条似乎与状态栏大小相同的线。我在下面列出了如何添加子视图,并附有屏幕截图来说明我的问题。
theLaunch = [[firstLaunch alloc] init];
[window addSubview:theLaunch.view]; // it goes on top
[window makeKeyAndVisible];
这是屏幕截图...下面的视图是灰色的。
I've got this strange bug in my app. I'm making a subview and drawing it over the top of my main view. To get rid of it I'd just hide it. Here's the problem: There I can see part of the view underneath peeking through the bottom in a line that seems to be the same size as the status bar. I've put how I'm adding my subview below, along with a screenshot to illustrate my problem.
theLaunch = [[firstLaunch alloc] init];
[window addSubview:theLaunch.view]; // it goes on top
[window makeKeyAndVisible];
Here's the screenshot...the view underneath is grey.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来您没有正确“锚定”子视图。如果在 IB 中,那么您可以尝试将子视图附加到包含视图的底部边缘。您的“主视图”似乎正在拉伸以容纳可用空间(状态栏的存在会改变),而您的“子视图”似乎位于(0,0)。像这样的东西可能会有所帮助:
以编程方式,您可以使用 UIView 的 autoresizingMask。比如:
我对这就是实际问题有多大信心?不像我希望的那样自信。
It looks like you don't have subview properly 'anchored'. If in IB, then you could try attaching subview to bottom edge of containing view. Your 'main view' seems to be stretching to accommodate available space (which is changed by presence of status bar), while you 'sub view' appears to be positioned (0,0). Something like this might help:
Programmatically, you could use UIView's autoresizingMask. Something like:
How confident am I that this is the actual problem? Not as confident as I would like to be.
您在哪里定义firstLaunch 的用户界面?如果它位于 nib 文件中,则需要
theLaunch = [[firstLaunch alloc] initWithNibName:@"firstLaunch" bundle:nil];
。如果您手动添加界面元素;你在哪里做这个?如果您在 ViewDidLoad 中手动添加它们,我想您应该会看到它。Where are you defining your user interface for firstLaunch? If it's in a nib file, you need to have
theLaunch = [[firstLaunch alloc] initWithNibName:@"firstLaunch" bundle:nil];
. If you are manually adding your interface elements; where are you doing that? If you're adding them manually in ViewDidLoad, I think you should be seeing it.您的图像可能在下图显示的地方具有 Alpha 透明度。如果您不想要这种效果,您应该重新创建不带 Alpha 的图像(完全不透明)。
如果您由于某种原因无法重新创建图像,您可以尝试将图像视图的不透明属性设置为“是”(我不确定这是否有效),或者在图像视图下方添加另一个视图,即不透明并且具有不透明的纯色背景。
Your image probably has alpha transparency in the places where the image below shows through. If you don't want that effect, you should recreate the image without alphas (fully-opaque).
If you aren't able to recreate the image for some reason, you could try either setting the opaque property of the image view to YES (I'm not sure if that will work), or adding another view below your image view that is opaque and has a solid background color that isn't transparent.