User interaction with uiview and animation complet

2019-02-13 15:08发布

I have the following code:

[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction
     animations:^{
         imageView.bounds = endBounds;
     }
     completion:^(BOOL finished) {
         [UIView animateWithDuration:2.0 delay:0.5 options:UIViewAnimationOptionAllowUserInteraction
              animations:^{
                  imageView.bounds = startBounds;
              }
              completion:^(BOOL finished) {
                      [imageView removeFromSuperview];
              }];
     }];

Additionally I have:

[imageView setUserInteractionEnabled:YES];

and a tap gesture recognizer set that will handle the user tapping on imageView. While the first animation is happening, the gesture recognizer fires as I would expect. But if I try and tap imageView during the chained animation from the completion block, nothing happens even though I have set the appropriate option.

Anyone have any thoughts? I've googled and can't find an answer.

3条回答
Root(大扎)
2楼-- · 2019-02-13 16:12

I came up with a solution:

I wrap the UIImageView in a UIView (I subclass UIView) with the same bounds/center point as the image. Then I attach the gesture recognizer to the wrapper, instead of the image. Because the wrapper's bounds rectangle/center point never change for the duration of the animation, it's always available as the target of a gesture.

This works quite well.

-j

查看更多
聊天终结者
3楼-- · 2019-02-13 16:13

When using the new animation blocks, if you want user interaction to be enabled during the animation, you have to set it in the options mask. For example:

[UIView animateWithDuration:1.0 
                      delay:0 
                    options:UIViewAnimationOptionAllowUserInteraction 
                 animations:^{ myView.alpha = 0.5; } 
                 completion:NULL];
查看更多
我只想做你的唯一
4楼-- · 2019-02-13 16:14

Do you see the same behaviour if you use:

+ [UIView setAnimationDidStopSelector:]

instead of using blocks?

查看更多
登录 后发表回答