【问题标题】:UIView Not Resizing On Roation When Using Autosizing使用自动调整大小时,UIView 不会在旋转时调整大小
【发布时间】:2014-08-13 00:01:02
【问题描述】:

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

谢谢

【问题讨论】:

    标签: ios objective-c uiview autoresizingmask


    【解决方案1】:

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

    [self.signupContainer setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
    

    UIImageView 也需要autoresizingMask

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

    【讨论】:

    • 那你又做错了。我的第一个猜测是您的视图控制器没有正确地在响应者链中,或者您在视图控制器方法实现中缺少对 super 的调用。
    • 谢谢,我也忘了自动调整“bgImageView”的大小,这样就不会扩展到包含视图的大小。
    猜你喜欢
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多