how to to make gesturerecognizer working in an animating UIImage view

后端 未结 3 1000
鱼传尺愫
鱼传尺愫 2021-01-19 21:18

i have 5 animating image in a image view and will like to allow user to tap on them base on the default ID and push it to another view. i tried to add in gesture tap but the

3条回答
  •  花落未央
    2021-01-19 22:08

    It is because that when animation is applying, the modification for any value of the sprite(UIImageView in your case) by animation is not applied to the sprite original, it is applied to its .layer.presentationLayer, the real one is still at its original place. In this case, you can try this: Put your gesture on the whole screen, when response comes from event, you check the touch point, make a hitTest to the presentationLayer, if yes then do what you want.

    I usually use below code to do that.

    - ( BOOL ) areYouThere: ( CGPoint ) point {
        return ( [ ( ( CALayer * )sprite.layer.presentationLayer ) hitTest: point ] != nil );
    }
    

    Get the touch point from a UITouch object when below method is invoked

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    

提交回复
热议问题