Animate UIView height from bottom to top

前端 未结 6 550
Happy的楠姐
Happy的楠姐 2021-02-02 17:35

I\'m doing a simple animation of UIView height so that it reveals.

By default it seems to be revealing from top to bottom, and I want it to reveal bottom to top.

<
6条回答
  •  旧巷少年郎
    2021-02-02 18:19

    Instead you could try putting it in a view with clipsToBounds = YES and then animate it from the bottom to the middle of the view, like so:

    viewToAnimate.frame = CGRectMake(viewToAnimate.frame.origin.x,
                                     viewToAnimate.superview.frame.size.height,
                                     viewToAnimate.frame.size.width,
                                     viewToAnimate.frame.size.height);
    
    [UIView animateWithDuration:0.5 animations:^{
         viewToAnimate.center = viewToAnimate.superview.center;
    }];
    

    This way, you don't have to set the height to 0, and it solves any problems with autoresizing within the view.

提交回复
热议问题