UIView动画在动画过程中确定中心
我正在使用 UIView 的 + animateWithDuration:delay:options:animations:completion: 方法在几秒钟左右的时间内沿着一条线移动我的视图。
我想在该动画期间的任意时间确定 UIView 及其移动路径的位置。但是,当我执行此操作并尝试访问 center
或 frame
时,我发现该位置已设置为其最终目的地。
我这样做的原因是我每 0.1 秒(或大约)触发一次 NSTimer,它将更新父视图以显示 UIView 之前所在的行。我希望能够随着 UIView 的移动而保持更新。
关于如何做到这一点有什么想法吗?我发现的唯一类似的问题是 http://forums.macrumors.com/showthread.php? t=1056105,但没有显示分辨率。
或者...有没有更好的方法来做到这一点?
谢谢!
I'm using UIView's + animateWithDuration:delay:options:animations:completion:
method to move my view along a line over the course of a few seconds or so.
I would like to determine, at an arbitrary time during this animation, where the UIView is along with path it is moving. However when I do this and try and access center
or frame
, I find that the location is already set to it's final destination.
The reason I'm doing this is that I've got an NSTimer firing every 0.1 seconds (or thereabouts) which will update the parent view to show a line where the UIView has previously been. I want to be able to keep this updated as the UIView moves.
Any ideas on how to do this? The only similar question I found was http://forums.macrumors.com/showthread.php?t=1056105, but there is no resolution shown.
Alternatively...are there any better ways to do this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIViews 由 CALayers 支持,它是执行实际动画的层。 CALayer 公开一个属性
presentationLayer
,该属性在访问时返回 CALayer 的副本,该副本尽可能接近地表示用户可见的当前状态。通过请求 view.layer.presentationLayer.frame ,您可以获得用户现在可见的图层框架,这对应于 UIView 的框架。UIViews are backed by CALayers, and it is the layer that does the actual animation. CALayer exposes a property
presentationLayer
which, when accessed, returns a copy of the CALayer that represents, as closely as it can, the current state visible to the user. By asking for theview.layer.presentationLayer.frame
you can get the frame of the layer as visible to the user right now, and this corresponds to the frame of the UIView.我知道为时已晚,但也许它可以帮助其他人。
CALayer 有一个presentation()函数
表示层有一个框架属性,即 CGRect,从这里可以轻松计算中点。
演示
swift 3 中的代码
I know its too late but maybe it can help somebody else.
CALayer has a presentation() function
the presentation layer has a frame property what is a CGRect and from here easy the calculate the midpoint.
Demo
The code in swift 3