Having problems allowing interaction in UIView animation

前端 未结 5 428
野趣味
野趣味 2021-01-03 12:23

I have the following block of code to fade out an introView(UIView)

// Hide intro view after 5 seconds
[UIView animateWithDuration: 1.0
          delay: 5.0
         


        
相关标签:
5条回答
  • 2021-01-03 12:58

    Are you setting your button alpha to 0?
    If yes here is an interesting thing about animation.

    What you see on the screen during the animation is not what the application sees. The moment you set your alpha to 0, the alpha is 0 for that view, even if you are still seeing it on the screen.
    Also, a view that has an alpha lower that 0.05 (don't recall the exact number) won't get touch event.

    What you can do is to implement the - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event of that view's superview. or the touchesEnded... as you like.
    (Assuming that your not setting it's alpha to 0.)

    So you can test for touche that occur where the button is, or just remove that button and let any touch on the screen cancel your animation.


    You may also be interested in this post:
    Core Animation, unexpected animated position and hitTest values

    0 讨论(0)
  • 2021-01-03 13:00

    This won't work in iOS 3.2 since Blocks are only available in iOS4
    you will have to use the standard animation techniques, in a separate thread so that you don't block the interface

    [UIView beginAnimations:nil context:nil];
    
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:view cache:YES];
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    [UIView setAnimationDuration:1.0];
    
    [view1 setHidden:TRUE];
    
    [UIView commitAnimations];
    
    0 讨论(0)
  • 2021-01-03 13:07

    I found another circumstance which could cause this. I haven't seen this answer anywhere else. It does not deal with alpha at all.

    If you use a delay in the call to UIView.animate(), then even if you specify the .allowUserInteraction option, the view does NOT receive touches during the delay period. I have no idea why, but I could help it by moving the code block to another function, and using a performSelector after the same delay seconds, and in the block I run the code without delay.

    0 讨论(0)
  • 2021-01-03 13:12

    Pretty sure this is impossible pre-4.0:

    UIView userInteractionEnabled Docs

    During an animation, user interactions are temporarily disabled for all views involved in the animation, regardless of the value in this property. You can disable this behavior by specifying the UIViewAnimationOptionAllowUserInteraction option when configuring the animation.

    There seems little point in targeting 3.2 in an app you haven’t released yet.

    0 讨论(0)
  • 2021-01-03 13:21

    I had the same problem with a button that I animated with changing the alpha. Cueing off VinceBurn's answer...

    What you see on the screen during the animation is not what the application sees. The moment >you set your alpha to 0, the alpha is 0 for that view, even if you are still seeing it on the >screen. AND view that have an alpha lower that 0.05 (don't recall the exact number) won't get touch >event.

    … the simple solution of just making the minimum alpha 0.1 instead of 0.0 worked for me:

    [UIView animateWithDuration:0.5
                              delay:0.0
                            options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction
                         animations:^{
                             self.myButton.alpha = 0.1f;
                         }
                         completion:^(BOOL finished){
                         }]
    

    Button registered the touchUpInside all the time with no additional method needed, and there was virtually no difference in appearance from taking the alpha to zero.

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