在 UIView 动画中允许交互时遇到问题
我有以下代码块来淡出 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 中有一个跳过按钮,但没有任何交互,我是否遗漏了一些东西?我必须添加这是一个针对 3.2 的通用应用程序,我正在使用 XCode 4.2
I have the following block of code to fade out an 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];
}];
I have a skip button inside the introVew but there is no interaction whatsoever, am I missing something? I have to add this is a Universal app targeting 3.2 and I'm using XCode 4.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(5)
您是否将按钮 alpha 设置为 0?
如果是的话,这里有一个关于动画的有趣的事情。
您在动画过程中在屏幕上看到的内容并不是应用程序看到的内容。
当您将 alpha 设置为 0 时,该视图的 alpha 为 0,即使您仍然在屏幕上看到它。
此外,alpha 低于 0.05(不记得确切的数字)的视图将不会收到触摸事件。
您可以做的是实现该视图的超级视图的 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
。或 touchesEnded...
如您所愿。
(假设您没有将其 alpha 设置为 0。)
因此您可以测试按钮所在位置发生的触摸,或者只是删除该按钮并让屏幕上的任何触摸取消您的动画。
您可能也对这篇文章感兴趣:
核心动画、意外的动画位置和 hitTest 值
我对通过更改 Alpha 进行动画处理的按钮也遇到了同样的问题。引用文斯伯恩的回答......
您在动画过程中在屏幕上看到的内容并不是应用程序看到的内容。当您将 alpha 设置为 0 时,该视图的 alpha 也为 0,即使您仍然在屏幕上看到它。
并且 alpha 低于 0.05(不记得确切的数字)的视图将不会获得触摸 > 事件。
…将最小 alpha 设置为 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 设为 0 在外观上几乎没有任何区别。
这在 iOS 3.2 中不起作用,因为块仅在 iOS4 中可用
您必须在单独的线程中使用标准动画技术,这样就不会阻塞界面
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[view1 setHidden:TRUE];
[UIView commitAnimations];
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
很确定这在 4.0 之前是不可能的:
UIView userInteractionEnabled 文档
在您尚未发布的应用程序中以 3.2 为目标似乎没有什么意义。
Pretty sure this is impossible pre-4.0:
UIView userInteractionEnabled Docs
There seems little point in targeting 3.2 in an app you haven’t released yet.