This is absolutely not a good way to solve this problem, but it did the trick for me.
I've got a scaling animation, where a view grows to scale 6.0, waits for 2 seconds and then scales back to 1.0.
The wait for 2 seconds is my part where I used the performSelector:withObject:afterDelay: which I couldn't pause.
This is the pause part:
[UIView animateWithDuration:0 delay:2.0 options:0 animations:^{
self.transform = CGAffineTransformMakeScale(6.0 + 0.001, 6.0 + 0.001);
} completion:^(BOOL finished) {
[self animateOutWithCompletion:completion];
}];
Make sure you are animation a change, thats why I add 0.001 (which you wont see, as it's a that little change).
UIView animations can be paused using this category:
@interface UIView (AnimationsHandler)
- (void)pauseAnimations;
- (void)resumeAnimations;
@end
@implementation UIView (AnimationsHandler)
- (void)pauseAnimations
{
CFTimeInterval paused_time = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil];
self.layer.speed = 0.0;
self.layer.timeOffset = paused_time;
}
- (void)resumeAnimations
{
CFTimeInterval paused_time = [self.layer timeOffset];
self.layer.speed = 1.0f;
self.layer.timeOffset = 0.0f;
self.layer.beginTime = 0.0f;
CFTimeInterval time_since_pause = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil] - paused_time;
self.layer.beginTime = time_since_pause;
}
Feel free to use this code, but as I said before, this is not a good way to solve this problem. It's just making use of the way UIView animations work and the possibility to pause these animations.