UIView,animateWithDuration和beginFromCurrentState的问题 [英] Troubles with UIView, animateWithDuration and beginFromCurrentState

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

问题描述

我有一个自定义视图,该视图必须跟踪用户的位置。我将以下代码放在 touchesBegan 以及 touchesMoved 中:

I have a custom view that has to track the user's location. I put the following code in touchesBegan, as well as in touchesMoved:

[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    cursorView.center = locationOfTouch;
} completion:^(BOOL finished){}];

对我来说似乎很简单。我希望该视图始终能够动画显示用户的当前位置,即使该位置已更改并且该视图仍处于动画状态(由于beginFromCurrentState选项)。

It seems fairly straightforward to me. I'd expect the view to always animate to the user's current location, even if that location is changed and the view is still animating (because of the beginFromCurrentState option).

但是,每个动画都完全完成。他们不会过渡到新动画,没有先完成,然后开始新动画。

Yet, each animation finishes completely. They don't 'transition' to the new animation, no they finish first, then they start the new animation.

我尝试在 touchesMoved :

[cursorView.layer removeAllAnimations];

什么也没做。没有动画被取消。有任何想法吗?

Doesn't do anything. No animation is cancelled. Any ideas?

推荐答案

[cursorView.layer removeAllAnimations]; 访问视图的图层,但您没有直接将动画设置为该图层,而是直接将视图设置为该图层。

尝试:

with [cursorView.layer removeAllAnimations]; you access the layer of the view but you have set the animation not to the layer but the view directly.
Try:

[UIView beginAnimations:nil context:NULL]
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
cursorView.center = locationOfTouch;
[UIView commitAnimations];

并省略 removeAllAnimations ,它应该从当前状态过渡。

and leave out the removeAllAnimations and it should transition from current state.

这篇关于UIView,animateWithDuration和beginFromCurrentState的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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