Question

I have a view with 2 container views: one main one on top and one at the bottom.

When the app launches, the bottom one is hidden via a frame that goes beyond the screen height. The top one in the meantime occupies the entire app window.

When I decide to show that bottom container, I want the top container to decrease in height and the view of the controller in that main container to be impacted as well.

I tried to add a constraint programmatically and used layoutIfNeeded but nothing worked.

I'm new to this. I don't necessarily want the best answer but how I should approach this.

Thanks!!!!

-(void)showBottom {
    NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self.bottomContainer attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.mainContainer attribute:NSLayoutAttributeTop multiplier:1.0f constant:49.0f];
    [self.view addConstraint:constraint];
}
Was it helpful?

Solution

You can try pinning objects with a Top Space to Superview constraint and animating it.

// .h
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;

// .m
[UIView animateWithDuration:1.0 animations:^{
    self.topConstraint.constant = 0;
    [self.nView layoutIfNeeded];
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top