【问题标题】:Touches getting lost when I animate inside of touchesBegan当我在 touchesBegan 内部制作动画时,触摸会丢失
【发布时间】:2011-03-06 17:24:22
【问题描述】:

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

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

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

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

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

【问题讨论】:

    标签: iphone ios uiview uitouch uiresponder


    【解决方案1】:

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

    options:UIViewAnimationOptionAllowUserInteraction
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多