how to to make gesturerecognizer working in an animating UIImage view

我是研究僧i 提交于 2019-12-01 19:03:06

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

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

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];
                 }
];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!