Tap Gesture on animating UIView not working

后端 未结 6 1819
南笙
南笙 2020-12-19 18:26

I have a tap gesture on a UILabel who\'s translation is being animated. Whenever you tap on the label during the animation there\'s no response from the tap gesture.

<
6条回答
  •  星月不相逢
    2020-12-19 18:53

    I was stuck on this problem for hours, and could not understand why the tapping did not work on an animated label which slides out of screen after 3 seconds delay.

    Well said agibson007, about the animation works like a fake movie's playback, the 3-second delay controls the payback of the movie, yet the label's frame is changed as soon as the animation begins without a delay. So the tapping (which depends on the label's frame at its original position) would not work.

    My solution was changing the 3-second delay to a timeout function like -

    DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
       [weak self] in
       self?.hideLabel()           
    }
    

    So that keeps the tapping works during the delay, and allow animation runs inside the hideLabel() call after the delay.

提交回复
热议问题