1

これが状況です。

回転時に画面にうまく調整される自動レイアウトを使用する UIScrollView がありますが、調整されない scrollView のコンテンツに問題があります。

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

AutoLayoutの代わりにフレームを使用しているため、scrollViewのコンテンツは調整されません。フレームを AutoLayout 制約に書き換えると、回転時に調整されます。予測できない結果になる可能性があるため、常に AutoLayout とフレームを混在させないようにしてください。

于 2013-04-16T18:24:12.770 に答える