how to to make gesturerecognizer working in an animating UIImage view

后端 未结 3 997
鱼传尺愫
鱼传尺愫 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
    
    0 讨论(0)
  • 2021-01-19 22:12

    Really late but I've been facing the same issue and I found what I think is a better solution:

    Just use the UIViewAnimationOptionAllowUserInteraction option like that:

    [UIView animateWithDuration:4.0
                          delay:0
                        options:UIViewAnimationOptionAllowUserInteraction
                     animations:^{ 
                         imageViewTop.alpha = 0.0;
                         imageViewBottom.alpha = 1.0;
                     } 
                     completion:^(BOOL  completed){
                         [self nextAnimation:stringsize.width];
                     }
    ];
    
    0 讨论(0)
  • 2021-01-19 22:18

    I would add a transparent view on top of the image view and add a gesture recognizer to that.

    0 讨论(0)
提交回复
热议问题