【问题标题】:viewcontroller and autolayout rotation issue视图控制器和自动布局旋转问题
【发布时间】:2014-09-01 20:05:12
【问题描述】:

您好,我正在使用以下代码创建自定义视图控制器层次结构。但是我在子视图中设置的自动布局似乎不起作用。当我旋转设备时,子视图不会拉伸以适应屏幕。

_postVC = [[POSTViewController alloc] initWithNibName:@"POSTViewController" bundle:nil];
[self addChildViewController:_postVC];
[_postVC didMoveToParentViewController:self];

[self.mainView addSubview:_postVC.view];

_postVC.view 在旋转后不会拉伸到与self.mainView 相同的宽度。

【问题讨论】:

    标签: ios autolayout viewcontroller


    【解决方案1】:

    你需要:

    _postVC.view.frame = self.mainView.bounds // 1 _postVC.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight // 2

    在添加_postVC.view 作为self.mainView 的子视图之前。

    这样,1._postVC.view 被设置为适合 self.mainView,并且 2._postVC.view 被配置为在调整 self.mainView 的大小时同时调整垂直和水平大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      相关资源
      最近更新 更多