2011-03-06 51 views
1

我想在屏幕上有4个UIViews,并在触摸时为它们的背景色设置动画,并在触摸结束时将其更改回来。当我在touches内动画时迷路了开始

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

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

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

如何用动画响应所有接触?我实际上喜欢每一个新的触摸来中断以前的动画......并重新开始。

回答

2

看起来我需要设置的块动画的选项

options:UIViewAnimationOptionAllowUserInteraction 
0

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

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { 
    [UIView beginAnimations:@"touchesBegan" context:nil]; 
    self.backgroundColor = altColor; 
    [UIView commitAnimations]; 
}