动画期间无法触摸(块动画)
我有一个带有 UIButton
、UITextField
的视图和一个用于背景的 UIImageView
。
在 viewDidLoad 中,我尝试使用块将 UIImageView
从 alpha=0 动画到 alpha =1。这是非常基本的,这是代码:
[UIView animateWithDuration:1.5 animations:^(void){
((UIView*)[self.view viewWithTag:123]).alpha = 1;
}completion:^(BOOL finished){
}];
运行良好。但在那 1.5 秒的动画中,我在当前视图中的触摸似乎被禁用了。在动画完成之前我无法单击任何按钮或文本字段。
提前致谢
I have a View with UIButton
, UITextField
, and a UIImageView
for Background.
in viewDidLoad
i try animate UIImageView
from alpha=0 to alpha =1 using block. it's pretty basic, here's the code:
[UIView animateWithDuration:1.5 animations:^(void){
((UIView*)[self.view viewWithTag:123]).alpha = 1;
}completion:^(BOOL finished){
}];
which is working fine. but during that 1.5 seconds of animation, my touch in current view seems to be disabled. i can't click any of the buttons or textFields until animation finish.
Thanks in Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您应该使用选项UIViewAnimationOptionAllowUserInteraction,如下例所示:
You should use option UIViewAnimationOptionAllowUserInteraction as in the following example:
对于 Swift 3+,iOS 10 使用 .allowUserInteraction 动画中的 UIView 用户交互
添加到动画调用 UIViewAnimationOptions 标志
.allowUserInteraction
UIView userinteraction in animation using .allowUserInteraction for Swift 3+,iOS 10
Add to the animation call the UIViewAnimationOptions flag
.allowUserInteraction
看起来动画按钮通常会使它们的点击状态变得非常挑剔。我为此提出的解决方案是让动画元素只是一个具有所有按钮样式的 UIView。在 UIView 动画之前,我向 UIView 上方的视图添加一个真实的按钮,并在我希望用户交互发生的位置提供清晰的背景。确实增加了一个额外的步骤,但非常可靠。
Seems like animating buttons in general makes their click states pretty finicky. The solution I came up with for this was to have the animating element just be a UIView with all the button styles. Before the UIView animates I add a real button to the view above the UIView with a clear background to the location I want the user interaction to occur. Definitely adds an extra step but is very dependable.
使用 animateWithDuration:delay:options:animations:completion: 方法并将 UIViewAnimationOptionAllowUserInteraction 设置为选项
Use
animateWithDuration:delay:options:animations:completion:
method and set UIViewAnimationOptionAllowUserInteraction as option我最终没有这样做。您无法触摸仍在动画的视图。这就是我的结论。不过,很高兴听到对此的一些想法。
I ended up not doing this. You can't touch a view that still animating. that's my conclusion. Would be happy to hear some thought on this though.
这不是发生在标准 iOS 应用程序上的事情吗,比如“设置后退按钮”、“菜单滑动”。在动画播放时无法触摸屏幕,而在 Android 中可以触摸。
Isn’t it something that happens on standart iOS apps like Settings back button, menu swipe. There is no way to touch to screen while it is animating whereas you can touch in Android.