&QUOT推送QUOT; Objective-C中的动画 [英] "Push" animation in Objective-C

查看:115
本文介绍了&QUOT推送QUOT; Objective-C中的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图:A和B. A位于屏幕顶部,B位于屏幕底部。

I have two views: A and B. A is positioned at the top of the screen, B is positioned at the bottom of the screen.

当用户按下按钮时,使用EaseInEaseOut bezier曲线向上查看B动画,直到达到y = 0.当B正在前往目的地时,它应该当它击中A时向上推A。换句话说,当B在从底部到顶部的过渡期间经过某个y坐标(A的y原点+高度)时,A应该粘在B上,所以看起来B向上推A。

When the user presses a button, view B animates upwards with a EaseInEaseOut bezier curve until it reaches y = 0. While B is on its way to its destination, it should push A up when it hits A. In other words, when B has passed a certain y coordinate (A's y origin + height) during its transition from bottom to top, A should stick to B so it seems B pushes A upwards.

到目前为止我尝试过:


  • 将目标+选择器注册到CADisplayLink用户按下按钮后立即。在此选择器内,通过访问其presentationLayer请求视图B的y坐标,并相应地调整A的y坐标。然而,这种方法结果不够准确:presentationLayer的帧落后于B在屏幕上的当前位置(这可能是因为-presentationLayer重新计算动画视图在当前时间的位置,这需要超过1帧) 。当我增加B的动画持续时间时,此方法可以正常工作。

  • 在用户按下按钮后立即将目标+选择器注册到CADisplayLink。在此选择器内,通过求解x =经过时间/动画持续时间(应该返回行进的距离/总距离)的贝塞尔方程来计算B的当前y坐标。我使用了Apple的开源UnitBezier.h( http: //opensource.apple.com/source/WebCore/WebCore-955.66/platform/graphics/UnitBezier.h )。但是,结果不正确。

  • Register a target + selector to a CADisplayLink immediately after the user pressed the button. Inside this selector, request view B's y coordinate by accessing its presentationLayer and adjust A's y coordinate accordingly. However, this method turns out to be not accurate enough: the presentationLayer's frame is behind on B's current position on the screen (this is probably because -presentationLayer recalculates the position of the animating view on the current time, which takes longer than 1 frame). When I increase B's animation duration, this method works fine.
  • Register a target + selector to a CADisplayLink immediately after the user pressed the button. Inside this selector, calculate B's current y coordinate by solving the bezier equation for x = elapsed time / animation duration (which should return the quotient distance traveled / total distance). I used Apple's open source UnitBezier.h for this (http://opensource.apple.com/source/WebCore/WebCore-955.66/platform/graphics/UnitBezier.h). However, the results are not correct.

有关我接下来可以尝试的建议吗?

Any suggestions on what I can try next?

推荐答案

你说你试过动画B并使用显示链接来更新A技术,并且它导致A落后于B。理论上你可以为新视图设置动画C,然后在显示链接中相应地调整B和A的帧,这应该消除任何延迟(相对于彼此)。

You said that you tried the "animate B and use display link to update A" technique, and that it resulted in "A" lagging behind "B". You could theoretically animate a new view, "C", and then adjust B and A's frames accordingly in the display link, which should eliminate any lag (relative to each other).

这篇关于&QUOT推送QUOT; Objective-C中的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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