1

这是情况。

我有一个使用自动布局的 UIScrollView,当我旋转它时,它成功地调整到屏幕上,我的问题在于滚动视图的内容没有调整。

scrollView 是红色部分。

1 2

这是我的代码:

-(void)preparePromotions
{

CGRect frameViewPromotions = [self getPossibleFrame];


    frameViewPromotions.origin.x = 10.0f;
    frameViewPromotions.origin.y = 10.0f;
    if (!_promotionsViewController)
    {
        _promotionsViewController = [[PromotionsViewController alloc] init];
    }
    _promotionsViewController.view.frame = frameViewPromotions;
    _promotionsViewController.margin = 2.0f;
    _promotionsViewController.diameterPageController = 10.0f;
    _promotionsViewController.marginPageController = 15.0f;
    _promotionsViewController.frameContentView = frameViewPromotions;

    [self addChildViewController:_promotionsViewController];

_promotionsViewController.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:_promotionsViewController.view];
[self createCosntraintWithView:_promotionsViewController.view];    

}


-(void)createCosntraintWithView:(UIView *)subview
{
NSDictionary *views = NSDictionaryOfVariableBindings(subview);

[self.view addConstraints:
 [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[subview]-10-|"
                                         options:0
                                         metrics:nil
                                           views:views]];

[self.view addConstraints:
 [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-40-[subview]-50-|"
                                         options:0
                                         metrics:nil
                                           views:views]];

}
4

1 回答 1

1

scrollView 的内容不会调整,因为您在那里使用的是框架,而不是 AutoLayout。如果您将框架重写为 AutoLayout 约束,它会在您旋转时进行调整。始终尽量避免混合 AutoLayout 和框架,因为您可能会得到不可预知的结果。

于 2013-04-16T18:24:12.770 回答