Animate UIView height from bottom to top

前端 未结 6 551
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:56

    Like a dog with a bone I figured this out....

    Instead of animating the frame height, I applied a transform to the view and set the anchor point of the layer.

    //set the anchor point to the bottom of the view
    [self setAnchorPoint:CGPointMake(0.5, 1.0) forView:hostView];
    //Scale the height to close to zero
    hostView.transform = CGAffineTransformMakeScale(1, 0.00001);
    

    If I put 0 as the y scale, the view behaves weird.... at the end of the animation i just set it to hidden.

    On the way back up I just use the Identity Transform (reset it)

    hostView.transform = CGAffineTransformIdentity;
    

    Note that changing my anchor point shifted the position of my view. See this post for the setAnchorPoint method which normalises the view after setting the anchorPoint

    Changing my CALayer's anchorPoint moves the view

提交回复
热议问题