- (void) startAnimator:(NSString *) pref endingWith: (int) end andFrame:(CGRect) rect {
//[viewController.view removeFromSuperview];
self.animatorViewController = [ImageAnimatorViewController imageAnimatorViewController];
NSArray *names = [ImageAnimatorViewController arrayWithNumberedNames:pref
rangeStart:1
rangeEnd:end
suffixFormat:@"%02i.png"];
NSArray *URLs = [ImageAnimatorViewController arrayWithResourcePrefixedURLs:names];
// setting the public property for our custom CGRect:
animatorViewController.viewCGRect = rect;
// we no longer need to provide an orientation //animatorViewController.animationOrientation = UIImageOrientationUp; // Rotate 90 deg CCW
animatorViewController.animationFrameDuration = ImageAnimator15FPS;
animatorViewController.animationURLs = URLs;
animatorViewController.animationRepeatCount = 0;
// Show animator before starting animation
// add the animatorViewController.view as a subView:
[self.view addSubview:animatorViewController.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(animationDidStartNotification:)
name:ImageAnimatorDidStartNotification
object:animatorViewController];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(animationDidStopNotification:)
name:ImageAnimatorDidStopNotification
object:animatorViewController];
[animatorViewController startAnimating];
}
[/cc]
Then lastly I commented out parts of the stopAnimator method so that the final frame of each animation would remain until I needed to dispose of it by using another method clearAnimation.
[cc lang="objc"]
- (void) stopAnimator {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:ImageAnimatorDidStartNotification
object:animatorViewController];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:ImageAnimatorDidStopNotification
object:animatorViewController];
[animatorViewController stopAnimating];
// [animatorViewController.view removeFromSuperview];
// self.animatorViewController = nil;
}
- (void) clearAnimation {
[animatorViewController.view removeFromSuperview];
self.animatorViewController = nil;
}