有UIViewanimation允许交互的问题

我有以下代码块淡出introView(UIView)

// Hide intro view after 5 seconds [UIView animateWithDuration: 1.0 delay: 5.0 options: (UIViewAnimationOptionAllowUserInteraction |UIViewAnimationOptionCurveLinear) animations: ^{ introView.alpha = 0; } completion: ^(BOOL finished) { [introView removeFromSuperview]; }]; 

我在introVew里有一个跳过button,但是没有任何交互,我错过了什么吗? 我必须添加这是一个通用的应用程序目标3.2和我使用XCode 4.2

你是否将你的button设置为0?
如果是的话,这是关于animation的一个有趣的事情

你在屏幕上看到的animation不是应用程序看到的。 将alpha设置为0的那一刻,即使您仍然在屏幕上看到alpha,该视图的alpha也是0。
此外,alpha值低于0.05的视图(不记得确切的数字)将不会得到触摸事件。

你可以做的是实现- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event该视图的- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event视图的- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 。 或touchesEnded...如你所愿。
(假设你没有把它设置为0)

因此,您可以testingbutton所在的位置,或只是移除该button,并让屏幕上的任何触摸取消您的animation。


您可能也对这篇文章感兴趣:
核心animation,意想不到的animation位置和hitTest值

可以肯定,这是不可能的4.0前:

UIView userInteractionEnabled Docs

在animation过程中,无论此属性中的值如何,用户交互都将暂时停用在animation所涉及的所有视图中。 您可以通过在configurationanimation时指定UIViewAnimationOptionAllowUserInteraction选项来禁用此行为。

在一个你还没有发布的应用中瞄准3.2似乎没有什么意义。

我有一个button的问题,我改变alpha的animation。 提示VinceBurn的答案…

你在屏幕上看到的animation不是应用程序看到的。 当你设置你的alpha为0时,即使你仍然在>屏幕上看到alpha,那么该视图的alpha值为0。 并且有一个低于0.05(不记得确切数字)的alpha视图将不会触碰>事件。

…简单的解决scheme,只是使最小阿尔法0.1而不是0.0为我工作:

 [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction animations:^{ self.myButton.alpha = 0.1f; } completion:^(BOOL finished){ }] 

Button不需要额外的方法就可以随时注册touchUpInside,而且从alpha到零的外观几乎没有什么区别。

这在iOS 3.2中将不起作用,因为Blocks仅在iOS4中可用
你将不得不使用标准的animation技术,在一个单独的线程,以便您不要阻止接口

 [UIView beginAnimations:nil context:nil]; [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:view cache:YES]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1.0]; [view1 setHidden:TRUE]; [UIView commitAnimations]; 

我发现了另一个可能导致这种情况的情况。 我没有在其他地方看到这个答案。 它根本不处理alpha。

如果在对UIView.animate()的调用中使用延迟,则即使指定.allowUserInteraction选项,视图也不会在延迟期间接收到触摸。 我不知道为什么,但我可以通过将代码块移动到另一个函数,并使用performSelector相同的延迟秒数,并在块中运行代码没有延迟帮助它。