Programmatically reveal a UIView

[亡魂溺海] 提交于 2019-12-06 03:46:27

It definitely is possible. What you need to do is

  • For the view you're animating, setAutoresizesSubviews:NO and setClipsToBounds:YES.
  • Set the view's bounds (NOT the frame) to a rect with zero size and origin at the center point of the rect you want the view to occupy when it is fully revealed (in the view's own coordinate system). In other words, startBounds.origin.x should equal half of endBounds.size.width and similarly for y.
  • Position the view by setting its center (in the parent view's coordinate system).
  • In an animation block, change the view's bounds to zero origin and full size.
  • In the animation's completion block, you probably want to setAutoresizesSubviews:YES again.

You may also need to set the view's autoresizing mask to be fully flexible (springs but no struts), depending on what other layout gets triggered as you resize.

Sounds like you want to change its clipping. A cheap (code-wise) way to do that would be to insert the view into a parent view (with autoresizing set to center it), set the parent to clip its children and then animate the parent's frame.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!