Question

I one view that should pop in, and animate from the bottom

Two screen, view pop in and hide

This view (shown in screenshot below) should hide and pop in. (screen 5->6 hide) (scree 6->5 pop in).

view in question

You can see that the UIWebView (the view with text is UIWebView), needs to be shrunken and stretched appropriately.

I wonder what is the proper way to do this. Should I create 320pt x 0pt view (that would be hidden because it have no height), and then animate it's "height" property, and update height constraints ? Or I should take different approach ?

I use storyboard system.

Thank you very much for time and answer

Was it helpful?

Solution

1) Design your screen like in view 5.

2) Set up the constraints with the "opened" height of the pop up view. The bottom of the view above needs to be connected to the top of the popup view and that top view shouldn't have a fixed height, obviously.

3) Create an outlet for the height constraint

4) In windowDidLoad store the "opened" height by getting it from the constraint (so that you don't have to maintain it separately in the code). For example (where _popUpHeight is a CGFloat member variable):

- (void)viewDidLoad
{
    _popUpHeight = _popUpHeightConstraint.constant; 
}

5) Animate the constraint when needed. Something like this:

- (IBAction)togglePopup:(id)sender {

    [UIView animateWithDuration:5
         animations:^{
                      _addBannerDistanceFromBottomConstraint.constant = (_popupState) ? 0 : _popUpHeight;
                 }];

    _popupState = !_popupState;
}

OTHER TIPS

Try this code:

[UIView animateWithDuration:duration
                       delay:delay
                    options:UIViewAnimationOptionCurveEaseInOut
                 animations:^(void) {
                     viewToChange.frame = CGRectMake(x, y, width, height);
                 }
                 completion:NULL];

You will need an outlet for viewToChange.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top