本文介绍了不知道为什么 UIView 被推高了大约 10px的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的 iPhone 应用程序,其中包含两个 .xib 文件.在应用程序完成启动时的应用程序委托中,我通过调用显示第一个 .xib 文件:

I've created a simple iPhone app which has two .xib files. In the app delegate at application did finish launching I display the first .xib file by calling:

[window addSubview:myView];

我对 UIButton 的 IBAction 执行相同的操作,将视图更改为 myView2.

and I do the same on an IBAction for a UIButton to change the view to myView2.

我发现当我运行应用程序时,两个视图都有一个大约 10 像素的白条.我还注意到按钮偏移了 10 个像素(大约).所以我的印象是,视图是从屏幕外 10 个像素处显示出来的,结尾很短.

What I'm finding is that there's a white bar of around 10 pixels when I run the app, for both views. I also notice that the buttons are offset by 10 pixels (approx.). So I get the impression that the view is being displayed from 10 pixels off the screen and ending short.

知道为什么会发生这种情况吗,我该如何修复它,或者我如何进一步调试正在发生的事情?我检查了我的 .xib 文件,它们占用了设备的整个高度(即没有白条),所以这看起来是 XCode 内部的问题.

Any idea why this might be happening, how I can fix it, or how I can further debug what's going on? I've checked my .xib files and they are consuming the full height of the device (i.e. no white bars), so this looks to be a problem inside XCode.

我已经稍微缩小了问题的范围.我正在使用两种方法来加载子视图.当我在 applicationDidFinishLaunching 中加载第一个视图时,一切都很好.但是,如果我用 [self originalView] 方法替换 window 的两条消息,那么一切都会变得有点混乱.

I've narrowed down the problem a little. I'm using two methods to load the subview. When I load the first view inside applicationDidFinishLaunching everything is fine. However, if I replace the two messages to window with the [self originalView] method, then everything goes a bit haywire.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    //[self originalView];  <- I want to use this instead of the following two lines

    // Override point for customization after app launch
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

}

-(void)endView{
    endV = [[EndViewController alloc] initWithNibName:@"EndView" bundle:nil];
    [window removeFromSuperview];
    [window addSubview:endV.view];
}
-(void)originalView{
    viewController = [[MyAppViewController alloc] init];
    [window removeFromSuperview];
    [window addSubview:viewController.view];

}

据我所知,我总是调用相同的代码行,无论它是在 applicationDidFinishLaunching 中还是在 [self originalView] 中,但似乎就像 window 变成了一个不同的对象.

From what I can see, I'm always calling the same lines of code, no matter if it's inside the applicationDidFinishLaunching or in [self originalView] but it seems like window is turning out to be a different object.

推荐答案

当以正常方式使用 UIViewController 时(即 将其推到 UINavigationController 上),它会调整其视图的框架.

When using a UIViewController the normal way (i.e. pushing it on a UINavigationController), it adjusts its view's frame.

由于您是手动添加子视图,因此您必须自己调整框架.原点在右上角(在状态栏的顶部).您想将视图向下移动 20 个像素.

Since you're adding the subview manually, you have to adjust the frame yourself. The origin is in the upper right corner (at the top of the status bar). You want to shift your view 20 pixels down.

这篇关于不知道为什么 UIView 被推高了大约 10px的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:58
查看更多