编程揭示一个UIView [英] Programmatically reveal a UIView

查看:117
本文介绍了编程揭示一个UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图揭示(通过动画)一个UIView。具体来说,我想表明的观点的中心部分,然后慢慢揭开它的外缘(有点像拉回来一帘)。

I am attempting to reveal (through animation) a UIView. Specifically I want to show the center portion of the view and then slowly reveal the outer edges of it (sort of like pulling back a curtain).

我第一次尝试是简单地设置边界RECT更小和动画它是视图的框架的全尺寸,但这并没有收到预期的效果,因为通过改变边界,我也改变帧。

My first attempt was to simply set the bounds rect to be smaller and animate it to be the full size of the view's frame, but this did not have the desired effect since by changing the bounds I was also changing the frame.

如果我试图做的不健全可能(至少不是以简单的方式),至少我希望能够有一些方法,使主视图固定相的子视图屏幕,而不是他们的父视图,父尺寸缩小(这将给类似的效果)。

If what I am trying to do does not sound possible (at least not in a simple manner), at least I would like to be able to have is some way to make the subviews of the main view stationary relative to the screen, NOT their parent view, as the parent resizes (this would give a similar effect).

任何想法?

感谢您,

-Matt

推荐答案

这绝对是可能的。你需要做的是

It definitely is possible. What you need to do is


  • 对于你的动画视图, setAutoresizesSubviews:NO setClipsToBounds:YES

  • 将视图边界(而不是框架),以获得所需的观点占据当它充分暴露(认为自己的坐标系中)矩形的中心点零大小和原点的正确。换句话说, startBounds.origin.x endBounds.size.width 等于一半,同样,对于

  • 通过设置中心视图位置(父视图的坐标系)。

  • 在动画块,更改视图的边界为零的起源和全尺寸。

  • 在动画的完成块,你可能想 setAutoresizesSubviews:YES 再次

  • 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.

这篇关于编程揭示一个UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆