Pvt*_*ker 1 uiview uigesturerecognizer ios animatewithduration swift
我有一个视图(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
}
}
}
Run Code Online (Sandbox Code Playgroud)
它有效,但在动画期间子视图 B 不会触发它们的单击事件。我怎样才能在动画过程中检测到那个单击?
你必须使用
animateWithDuration(_ duration: NSTimeInterval,
delay: NSTimeInterval,
options: UIViewAnimationOptions,
animations: () -> Void,
completion: ((Bool) -> Void)?)
Run Code Online (Sandbox Code Playgroud)
为了那个原因。并提供AllowUserInteraction一个选项以允许用户在动画期间与视图交互。
有关更多选项,请参阅文档。
| 归档时间: |
|
| 查看次数: |
1016 次 |
| 最近记录: |