0

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];
}
2
  • Show how you are adding the constraint Commented Jan 18, 2014 at 0:26
  • So I want to call that method and have the constraint be applied. Not sure how I do this. This method is within the controller whose view holds the 2 containers. Commented Jan 18, 2014 at 1:39

1 Answer 1

1

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];
}];
Sign up to request clarification or add additional context in comments.

5 Comments

Do I need an animation for this? Can't I just do what I did above and then call layoutIfNeeded?
You can but it will just appear suddenly.
Thanks. Still having trouble with it. Will keep at it
Actually I have tried something else where I reassign the frame. It seems to work. Now my problem is that a table view from a controller embedded in the main container gets cut off and doesn't readjust. Have to figure that one out.
Found a way by adding a constraint via the storyboard on the table view and the bottom of the view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.