使用自动调整大小时,UIView不会在旋转时调整大小

时间:2014-08-12 15:44:08

标签: ios objective-c uiview autoresizingmask

我有一个以横向模式启动的应用程序,我创建了以下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中使用自动调整没有问题。

由于

1 个答案:

答案 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];