【问题标题】:How to Auto Resize , UIView Outlet in UIViewController in Interface Builder如何在 Interface Builder 中的 UIViewController 中自动调整 UIView Outlet 的大小
【发布时间】:2015-08-22 16:42:38
【问题描述】:

我有 UIView 大小设置为 w Any 和 h Any 的 .xib。问题是它没有正确调整大小。我还在.xib 中使用自动布局。目前只有一个视图(UIViewController的视图出口)。

我正在寻找为具有多种分辨率的屏幕调整大小的视图,例如:640 * 480、720 * 480、1024 * 768 等。

因此,如果执行以下操作,则调整大小不起作用。

Controller *myController=[[Controller alloc]  initWithNibName:@"Controller" bundle:nil];
[myBaseView addSubview:myController.view];

我还尝试将“内容压缩阻力优先级”设置为 1,这将允许它以较小的阻力调整大小。

但是,以下工作

UIView *aTestView=[[UIView alloc] initWithFrame:myBaseView.bounds]];
 [myBaseView addSubview: aTestView];

【问题讨论】:

    标签: ios autolayout interface-builder iboutlet


    【解决方案1】:

    您需要设置视图控制器的视图框架:

    Controller *myController=[[Controller alloc]  initWithNibName:@"Controller" bundle:nil];
    [myController.view setFrame:superViewFrame];
    [myBaseView addSubview:myController.view];
    

    【讨论】:

    • 这很简单。但是,我认为 autoresize 会考虑 baseView 框架并调整大小。
    • 当你使用 addSubview 方法来展示你的视图,它开启了自动布局,它不会用正确的尺寸来布局视图以匹配父尺寸,就像使用 presentViewController 或 pushViewController 的情况一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2016-07-15
    • 2014-05-26
    相关资源
    最近更新 更多