Animate UIView height from bottom to top

前端 未结 6 537
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 17:53

    I really think the simplest way to accomplish this would be to animate BOTH the height and the y properties of the view. If they happen along the same curve, it should look completely seamless to the user. As you are animating the height to 0, also animate the y component to the original y + the original height.

    UIView *view = ...;
    float originalY = view.frame.origin.y;
    float originalH = view.bounds.size.height;
    
    [UIView animateWithDuration:1.2f delay:1.0f options:UIViewAnimationCurveEaseInOut animations:^{
        view.frame = CGRectMake(view.frame.origin.x, (originalY + originalH), view.bounds.size.width, 0);
    
    }completion:^(BOOL finished) {
        NSLog(@"Animation is complete");
    }];
    

    I believe this would give the look and feel of a collapsing view. I haven't tried this out in code, but I see no reason why it wouldn't be possible like this.

提交回复
热议问题