1

我想在屏幕上有 4 个 UIView 并在触摸时为其背景颜色设置动画,并在触摸结束时将其更改回来。

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    [UIView animateWithDuration:0.1
        animations:^{
            self.backgroundColor = altColor;
        }];
}

不幸的是,当我在 touchesBegan 中执行此动画时 - touchesEnded 不会触发,除非在动画完成后触摸结束。这意味着 touchesEnded 在动画期间会因触摸而丢失。

此外,快速点击 UIView 不会导致多次 touchesBegan 调用。在动画(在第一次触摸中产生)完成之前,似乎没有收到新的触摸。

如何用动画响应所有触摸?实际上,我希望每次新的触摸都能打断之前的动画……然后重新开始。

4

2 回答 2

2

看起来我需要在块动画上设置一个选项

options:UIViewAnimationOptionAllowUserInteraction
于 2011-03-07T01:22:24.010 回答
0

事实证明,这种旧类型的动画似乎并没有阻止新的 touchesBegan 或 touchesEnded:

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    [UIView beginAnimations:@"touchesBegan" context:nil];
    self.backgroundColor = altColor;
    [UIView commitAnimations];
}
于 2011-03-06T18:18:06.267 回答