我有一个以横向模式启动的应用程序,我创建了以下UIView来全屏显示。
- (void)loadSignupScreen {
CGFloat screenHeight = self.view.frame.size.height;
CGFloat screenWidth = self.view.frame.size.width;
self.signupContainer = [[UIView alloc] initWithFrame:self.view.bounds];
[self.signupContainer setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin];
UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
[bgImageView setBackgroundColor:[UIColor darkGrayColor]];
[bgImageView setAlpha:0.8];
[self.signupContainer addSubview:bgImageView];
[self.view addSubview:self.signupContainer];
}
问题在于,当我将屏幕旋转到肖像时,它不是全屏而是它似乎只是屏幕长度的3/4左右。如何让它在旋转时填满屏幕?在编程时,我在IB中使用自动调整没有问题。
由于
答案 0 :(得分:2)
您正在为autoresizingMask
分配错误的signupContainer
。它应该是灵活的高度和宽度。
[self.signupContainer setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
UIImageView
还需要一个autoresizingMask
。
UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
[bgImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];