键值在UIView动画期间观察 [英] Key value Observing during UIView Animations

查看:146
本文介绍了键值在UIView动画期间观察的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序中动画一个视图的中心属性。在动画期间,当中心点击特定值时,我需要通知。



我尝试将自己添加为视图的中心属性的关键值观察者。但是,我只有当动画开始时通知。所以我无法检测对象是否通过我的兴趣点。



有没有办法通过KVO或任何其他方法? p>

谢谢!

解决方案

您可以检索代表当前状态的值UIView的动画层通过访问它的表示层。这可以使用如下代码:

  CGPoint currentCenter = [[view.layer presentationLayer] center]; 

不幸的是,表示层的属性不符合KVO,因此我可以想到的跟踪当前值是保持轮询表示层,直到它接近你想要的位置。


I'm animating the center property of a view in my program. During the animation, I need notifications when center hits a particular value.

I tried adding the myself as a key value observer for the center property of the view . However, I only get notified when the animation begins. So I'm unable to detect if/when the object passes through my point of interest.

Is there a way to do this through KVO or any other method?

Thanks!

解决方案

You can retrieve the values representing the current state of the UIView's animating layer by accessing its presentation layer. This can be done using code like the following:

CGPoint currentCenter = [[view.layer presentationLayer] center];

Unfortunately, the presentation layer's properties are not KVO-compliant, so the best way I can think of for tracking the current value is to keep polling the presentation layer until it gets near the location you want.

这篇关于键值在UIView动画期间观察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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