0

okay say I have a round rect button and an action method connected to it -(IBAction)btnclicked:(id)sender. When the button is pressed, it fires an animation. I used this in the action method I mentioned above--imageview.animationImages = images;. Here imageview is a pointer to UIImageView object and images is an array of images. Now what I want is that the button should remain disabled while the animation is going on. For that I tried this:

if (imageview) {
    btn.enabled = NO;
}

This of course disables the button but how should I enable it back after the animation is over. I thought of using NSTimer and disable the button for same time as animation but thats not a good method(its difficult to sync this timer with the animation). Besides, it also leaves the animation disabled after the animation is over. So please tell me if there is any good way to do what I'm trying? Thanks

Sahil Chaudhary
  • 493
  • 2
  • 10
  • 29
  • You could have the animation disable _all_ user interaction during the animation. Then it will automatically enable it after the animation. Would that work for you? – David Rönnqvist Jul 17 '12 at 09:34
  • yeah, that will work! How do I do that? – Sahil Chaudhary Jul 17 '12 at 09:48
  • when using the block-based animation methods all user interaction is disabled by default see [link](http://stackoverflow.com/questions/5748337/preventing-user-input-during-uiview-animations). – werner Jul 17 '12 at 10:00
  • I used the animation block:'[UIView animateWithDuration:3.2 delay:0.0f options:UIViewAnimationCurveLinear animations:^{imageview.animationImages = images;} completion:]; [imageview startAnimating]; [self.view addSubview:imageview]' But firstly animation goes on for forever and there is still user interaction. Any mistake? – Sahil Chaudhary Jul 17 '12 at 10:27
  • did you get your answer. let us know also, dude – nfarshchi Jul 18 '12 at 06:36
  • nope, animation block keeps my animation go on forever and if conditions may disable the button but I don't know how to enable it back! I mean I know how to but where should I? – Sahil Chaudhary Jul 18 '12 at 06:54

3 Answers3

0

The best way to solve this kind of situation is to implement a UIAnimation with a completion block. Take a look at this post on SO.

Hope this helps.

Community
  • 1
  • 1
werner
  • 859
  • 4
  • 8
0

you can use

if ( !imageview.isAnimating) {
  btn.enabled = Yes;
}

this property become No when animating is finished. so it means after the animation your btn become enable. only you need to disable it at the start of animation.

I hope this could help

nfarshchi
  • 990
  • 1
  • 8
  • 25
0

I think Animation Completion block is what you are looking for,

[UIView animateWithDuration:0.5
                          delay:0.1
                        options: UIViewAnimationOptionCurveEaseOut
                     animations:^
     {
         // Your animation
     }
                     completion:^(BOOL finished)
     {
         //Here do whatever you like after animation ends
     }];

Ref:- https://stackoverflow.com/a/14900987/3411787

Community
  • 1
  • 1
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130