首页 > 解决方案 > 当动画Swift时,点击手势在UIImageview上不起作用

问题描述

我制作了一个动画,我的图像视图使用 UIView.animate 从右向左滑动。我想在动画期间点击图像视图,但我不能。

顺便说一下,cloud是一个带有 imageviews 的容器视图。我会给容器视图动画。

tapImage = UIPanGestureRecognizer(target: self, action:#selector(goToDetail))
self.imgView1.addGestureRecognizer(tapImage!)

func animateTheClouds(cloud : UIView) {
    let cloudMovingSpeed = 3.0/view.frame.size.width
    let duration = (cloud.frame.origin.x + cloud.frame.size.width) * cloudMovingSpeed
    UIView.animate(withDuration: TimeInterval(duration), delay: 0.0, options: [.curveLinear,.allowUserInteraction,.allowAnimatedContent], animations: {
        cloud.frame.origin.x = -cloud.frame.size.width
    }, completion: {_ in
        // Reset back to the right edge of the screen
        if cloud.frame.origin.x <= 0{
            self.createGroupKanjiList()
            self.setImages()
            cloud.frame.origin.x = self.view.frame.size.width
        }
        self.animateTheClouds(cloud: cloud)
    })
}

标签: iosswiftanimationimageviewtap

解决方案


推荐阅读