我的观点是显示y = -20 dispite,其框架设置为y = 0。旋转后,它会快速回到y = 0 [英] My view is displaying y=-20 dispite its frame set to y=0. After rotation it snaps back to y=0
问题描述
我开始创建一个基于通用窗口的应用程序。从iPhone版开始,我创建了一个UIViewController和相关的nib。
I started by creating a universal window based app. Starting with the iPhone version I created a UIViewController and associated nib.
我的应用代表:
rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[window makeKeyAndVisible];
[window addSubview:rootViewController.view];
return YES;
我的RootViewController:
My RootViewController:
- (void)viewDidLoad {
[super viewDidLoad];
adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero()];
[self.view addSubview:adBannerView];
}
我尝试过实验按钮而不是adBanner,我得到相同的结果。
I've tried instanciating buttons instead of the adBanner and I get the same result.
我的RootViewController的nib没有被更改,因为x-code为我创建了它。
我的MainWindow_iPhone.xib也是股票。
My RootViewController's nib has not been changed since x-code created it for me. My MainWindow_iPhone.xib also is stock.
造成这种情况的原因是什么?
What's causing this?
更新
更改应用程序的方向后,adBannerView(或按钮...)将在y = 0处捕捉到正确的位置。我已经尝试将adBannerView的y位置设置为20,可能是为了补偿状态栏,这使得所有内容都能正确显示,直到我改变方向。然后一切都向下移动20个像素,并在adBannerView和状态栏之间留出20个像素的空间。
After changing the app's orientation the adBannerView (or button...) will snap into the correct place at y=0. I've tried setting adBannerView's y location to 20 presumably to compensate for the status bar and that makes everything display correctly until I change orientation. Then everything moves down 20 pixels and will leave a 20 pixel space between the adBannerView and the status bar.
推荐答案
尝试添加 viewDidLoad
中的下一行(在 [super viewDidLoad];
之后):
Try to add the next line in your viewDidLoad
(right after [super viewDidLoad];
):
self.view.frame = [[UIScreen mainScreen] applicationFrame];
这篇关于我的观点是显示y = -20 dispite,其框架设置为y = 0。旋转后,它会快速回到y = 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!