在UIView.animateWithDuration()期间为手势识别器启用用户交互

时间:2015-06-07 20:37:36

标签: ios swift uiview uigesturerecognizer animatewithduration

我有一个视图(A),它包含几个矩形子视图(B)。这些子视图中的每一个都有一个点击识别器来触发操作。父视图A还具有单个点击识别器,其调用A的控制器上的功能以使每个子视图B以彩色闪烁。这是功能:

@IBAction func highlightAreas(recognizer: UITapGestureRecognizer) {
    for area in buttons {
        // only show linked areas
        if area.targetPage != nil {
            let oldColor = area.backgroundColor

            // show areas with animation
            UIView.animateWithDuration(HIGHLIGHT_ANIMATION_TIME, animations: { Void in  // begin of closure
                area.backgroundColor = self.HIGHLIGHT_BACKGROUND_COLOR.colorWithAlphaComponent(self.HIGHLIGHT_ALPHA)
            })  // end of closure

            // hide areas with animation
            UIView.animateWithDuration(HIGHLIGHT_ANIMATION_TIME, animations: { Void in  // begin of closure
                area.backgroundColor = oldColor?.colorWithAlphaComponent(0.0)
            })  // end of closure
        }
    }
}

它可以工作,但在动画期间,子视图B不会触发他们的单击事件。如何在动画过程中检测单击?

1 个答案:

答案 0 :(得分:4)

你必须使用

animateWithDuration(_ duration: NSTimeInterval,
                         delay: NSTimeInterval,
                       options: UIViewAnimationOptions,
                    animations: () -> Void,
                    completion: ((Bool) -> Void)?)

为此。并提供AllowUserInteraction作为选项,允许用户在动画期间与视图进行交互 有关更多选项,请参阅the docs