iPhone Flip 转换 - 我可以在中途收到通知吗

发布于 2024-08-17 05:43:33 字数 305 浏览 11 评论 0原文

我有一个 UIView 用于绘制一组项目中的任何一个。也就是说,我的一个 UIView 子类可以被告知绘制一个正方形、圆形或三角形。

我想要一个过渡来翻转该视图,以便 UIView 在中途点绘制不同的形状,所以看起来我正在过渡到不同的视图,但实际上我只是在重绘单个视图过渡的中间点。

有没有办法做到这一点,而不需要使用两个不同的 UIView 并在动画块中交换它们?对我来说,重新调整我必须使用交换机制的东西会有点笨拙。

理想情况下,我需要的只是一些回调或通知,表明动画处于中间点,然后我可以使用新形状重新绘制视图。

感谢您的帮助!

I have a single UIView for drawing any one of a set of items. That is, my one UIView subclass can be told to draw a square, circle, or triangle for example.

I'd like to have a transition to flip that view so that the UIView draws a different shape at the half way point, so it looks like I'm transitioning to a different view, but really I'm just redrawing the single view at the half way point of the transition.

Is there a way to do this, without resorting to using two different UIViews and swapping them out in the animation block? It would be a bit clumsy for me to rejig what I have to use the swap mechanism.

Ideally all I need is some callback or notification that the animation is at the half way point, and then I can redraw the view with the new shape then.

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空宴 2024-08-24 05:43:33

即使您确实知道翻转动画的中点,我也不相信重新绘制动画中间视图的内容会做任何事情。我认为视图层的内容在动画开始时缓存,并且不会随着动画的进行而改变。此外,如果您的视图后面没有其他视图,那么在动画结束时您的视图最终会从左到右反转。

如果您希望将其作为自定义动画,您可以使用 Mike Lee 的 狐猴翻转实现,我在 这个答案。动画的前半部分结束后,您可以重新绘制视图的内容并完成动画,最后回到开始的地方。

然而,对我来说,不根据转换而切换视图似乎更笨拙。这肯定需要更多的代码来完成。

Even if you did know the midpoint of your flip animation, I don't believe redrawing the content of the view mid-animation would do anything. I think that the contents of the view's layer are cached at the beginning of the animation and don't change as the animation proceeds. Also, your view would end up inverted, left to right, at the end of the animation if you didn't have another view behind it.

If you wish to do this as a custom animation, you could break this into two halves using something like Mike Lee's Lemur Flip implementation that I describe in this answer. After the first half of the animation, you could redraw the view's content and complete the animation, ending up back where you started.

However, to me it seems more clumsy to not switch views in response to the transition. It certainly will take a lot more code to do.

温折酒 2024-08-24 05:43:33

你可以尝试这样做。例如,您的animationDuration属性设置为2.0f。所以,中间点是 1 秒,所以你可以使用

[self PerformSelector:@selector(yourCallbackMethod) withObject:nil afterDelay:1.0f];

you can try to do smth like this. For example, your animationDuration property is set to 2.0f. so, the half way point is 1 second, so you can use

[self performSelector:@selector(yourCallbackMethod) withObject:nil afterDelay:1.0f];

百善笑为先 2024-08-24 05:43:33

据我所知,您可以执行此操作的唯一方法是使用核心动画重新创建动画,然后使用计时器监视演示层中的动画。核心动画层中没有可用的 KVO,因此您必须显式监视它。

换句话说,这可能不值得。我建议你想一个不同的方法来解决你的问题。

The only way I know of that you could do this is to re-create the animation using Core Animation and then monitor the animation in the presentationLayer using a timer. There is no KVO available in Core Animation Layers so you have to monitor it explicitly.

In other words, it's probably not worth it. I suggest you think of a different way to solve your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文