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

标签 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 中的自动调整大小没有问题。

谢谢

最佳答案

您将错误的 autoresizingMask 分配给了 signupContainer。它应该只是灵活的高度和宽度。

[self.signupContainer setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

此外,UIImageView 需要一个 autoresizingMask

UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
[bgImageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

关于ios - 使用自动调整大小时,UIView 不会在旋转时调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25268625/

相关文章:

ios - 将 SKCameraNode 用于通用应用程序 SWIFT

ios - AVAssetResourceLoader 支持的 AVURLAsset 播放仅通过 AirPlay 失败

ios - 从另一个在后台播放的应用程序录制音频

ios - 使用 UIScreenEdgePanGestureRecognizer 扩展 PKRevealController

ios - 使用GAP Socket进行通信。编译器说未找到 PGPlugin.h

iphone - 当我在 Cocoa Touch 中加载一个新 View 时,它会将所有内容向上移动大约 20 像素

objective-c - Cocoa:改变 cocoa 向用户报告模型验证错误的方式

UIView CGGradient 剪切到绘制的 "frame"

objective-c - 如何在我的应用程序中的 iOS 键盘上创建自定义按钮?

ios - UICollisionBehavior的问题