不知道为什么UIView被大约10px轻推 [英] Not sure why UIView is being nudged up by around 10px

查看:191
本文介绍了不知道为什么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];

我在IBAction上为UIButton做同样的事情,将视图更改为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轻推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆