【问题标题】:view does not resize even after implementing shouldAutorotateToInterfaceOrientation即使在实现 shouldAutorotateToInterfaceOrientation 后视图也不会调整大小
【发布时间】:2025-12-06 18:00:01
【问题描述】:

对于我的代码, shouldAutorotateToInterfaceOrientation 被调用并且我在那里返回 YES 但是当我旋转设备时,控制器的视图会改变它的大小,但是主视图内的 UIImageView 不会改变它的大小。我希望它像主视图一样调整大小。

提前致谢

【问题讨论】:

    标签: iphone ios ios4 ios5


    【解决方案1】:

    根据您的需要设置autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
    在代码中

    imageview = [[UIImageView alloc] initWithFrame:CGRectMake(40,40,120,100)];
    imageview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
    


    如果您在 xib 中创建然后在 IB 中设置
    如下图所示

    【讨论】:

    • 你在 IB 或编码中创建了这个??
    • 来自代码.. imageview = [[UIImageView alloc] initWithFrame:CGRectMake(40,40,120,100)];
    • 非常感谢。我在代码“autoresizingMask”中添加了这一行,它正在工作......!!
    最近更新 更多