Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Here's the situation.

I have an UIScrollView that uses autolayout that successfully adjust to the screen when I rotate it, my problem comes with the scrollView's content that doesn't adjust.

The scrollView is the red part.

1 2

Here's my code:

-(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]];

}
share|improve this question

1 Answer

The scrollView's content doesn't adjust, because you're using frames there, instead of AutoLayout. If you rewrite your frames to AutoLayout constraints, it'll adjust when you rotate it. Always try to avoid mixing AutoLayout and frames, as you can get unpredictable results.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.