当我在 TouchBegan 内部设置动画时,触摸丢失
我想在屏幕上有 4 个 UIView,并在触摸时为其背景颜色设置动画,并在触摸结束时将其更改回来。
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[UIView animateWithDuration:0.1
animations:^{
self.backgroundColor = altColor;
}];
}
不幸的是,当我在touchesBegan中执行此动画时,除非动画完成后触摸结束,否则touchesEnded不会触发。这意味着在动画过程中,touchesEnded 会丢失触摸。
此外,快速点击 UIView 不会导致多次 TouchBegan 调用。似乎在动画(在第一次触摸中生成)完成之前不会收到新的触摸。
如何用动画响应所有触摸?我实际上希望每次新的触摸都会中断之前的动画......并重新开始。
I'd like to have 4 UIViews on the screen and animate their background color when touched and change it back when touches end.
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
[UIView animateWithDuration:0.1
animations:^{
self.backgroundColor = altColor;
}];
}
Unfortunately, when I perform this animation in touchesBegan - touchesEnded won't fire unless the touch ended after the animation completed. This means that touchesEnded gets lost for touches during the animation.
In addition, rapidly hitting the UIView doesn't result in multiple touchesBegan invocations. It seems that no new touches are received until the animation (spawned in the first touch) completes.
How can I respond to all touches with animations? I'd actually like each new touch to interrupt the previous animation ... and start it over again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来我需要在块动画上设置一个选项
Looks like I need to set an option on the block animation
事实证明,这种旧类型的动画似乎并没有阻止新的touchesBegan或touchesEnded:
Turns out that this older type of animation doesn't seem to block new touchesBegan or touchesEnded: