用户与 uiview 和动画完成块的交互

发布于 2024-10-20 06:23:41 字数 789 浏览 1 评论 0原文

我有以下代码:

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

少年亿悲伤 2024-10-27 06:23:41

使用新的动画块时,如果您希望在动画期间启用用户交互,则必须在选项蒙版中进行设置。例如:

[UIView animateWithDuration:1.0 
                      delay:0 
                    options:UIViewAnimationOptionAllowUserInteraction 
                 animations:^{ myView.alpha = 0.5; } 
                 completion:NULL];

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:

[UIView animateWithDuration:1.0 
                      delay:0 
                    options:UIViewAnimationOptionAllowUserInteraction 
                 animations:^{ myView.alpha = 0.5; } 
                 completion:NULL];
月亮坠入山谷 2024-10-27 06:23:41

我想出了一个解决方案:

我将 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

夜还是长夜 2024-10-27 06:23:41

您是否会看到相同的行为?

+ [UIView setAnimationDidStopSelector:]

如果您使用:而不是使用块,

Do you see the same behaviour if you use:

+ [UIView setAnimationDidStopSelector:]

instead of using blocks?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文