用户与 uiview 和动画完成块的交互
我有以下代码:
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction
animations:^{
imageView.bounds = endBounds;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 delay:0.5 options:UIViewAnimationOptionAllowUserInteraction
animations:^{
imageView.bounds = startBounds;
}
completion:^(BOOL finished) {
[imageView removeFromSuperview];
}];
}];
另外我有:
[imageView setUserInteractionEnabled:YES];
和一个点击手势识别器集,它将处理用户点击 imageView 的情况。当第一个动画发生时,手势识别器会按我的预期触发。但是,如果我尝试在完成块的链接动画期间点击 imageView,即使我设置了适当的选项,也不会发生任何情况。
有人有什么想法吗?我用谷歌搜索但找不到答案。
I have the following code:
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction
animations:^{
imageView.bounds = endBounds;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:2.0 delay:0.5 options:UIViewAnimationOptionAllowUserInteraction
animations:^{
imageView.bounds = startBounds;
}
completion:^(BOOL finished) {
[imageView removeFromSuperview];
}];
}];
Additionally I have:
[imageView setUserInteractionEnabled:YES];
and a tap gesture recognizer set that will handle the user tapping on imageView. While the first animation is happening, the gesture recognizer fires as I would expect. But if I try and tap imageView during the chained animation from the completion block, nothing happens even though I have set the appropriate option.
Anyone have any thoughts? I've googled and can't find an answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用新的动画块时,如果您希望在动画期间启用用户交互,则必须在选项蒙版中进行设置。例如:
When using the new animation blocks, if you want user interaction to be enabled during the animation, you have to set it in the options mask. For example:
我想出了一个解决方案:
我将 UIImageView 包装在 UIView 中(我是 UIView 的子类),其边界/中心点与图像相同。然后我将手势识别器附加到包装器,而不是图像。由于包装器的边界矩形/中心点在动画持续时间内不会改变,因此它始终可用作手势的目标。
这非常有效。
-j
I came up with a solution:
I wrap the UIImageView in a UIView (I subclass UIView) with the same bounds/center point as the image. Then I attach the gesture recognizer to the wrapper, instead of the image. Because the wrapper's bounds rectangle/center point never change for the duration of the animation, it's always available as the target of a gesture.
This works quite well.
-j
您是否会看到相同的行为?
如果您使用:而不是使用块,
Do you see the same behaviour if you use:
instead of using blocks?