I have a menu with items popping right after each other in intervals of 3 seconds, I'm doing it like so:
for(UIButton *menuItem in menuItems){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (0.3 * i) * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[menuItem setAlpha:1.0];
}
}
Is it possible to stop the animation in the middle (when a button is touched, for example) ? I tried just setting everything to alpha 1.0 but as expected, the threads kept running and shows the items again.
Would appreciate any ideas:)
Shai.
You could do the animations using UIView block-based animations, with the delay:
set. No thread worries there.
These animations can be interrupted by starting another block-based animation with the option UIViewAnimationOptionBeginFromCurrentState
set.
For alpha transitions this is fine since it doesn't matter what the current position of the animation is. If you are moving objects, you can get the current position by querying the view.layer.presentationLayer
which holds the current state of the object. You will need to import the QuartzCore framework to do this. This also gives you a method, removeAllAnimations
which will do pretty much what it sounds like and takes any view right to the endpoint of any animations it has got pending or active.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With