I am making an app that has a lot of animations and nested animations.
self.countDownAnimationImage = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"3" ofType:@"png"]]];
if([self.deviceType isEqualToString:@"iphone"])
{
self.countDownAnimationImage.frame = CGRectMake(120, 200, 80, 120);
}
else if([self.deviceType isEqualToString:@"iphone5"])
{
self.countDownAnimationImage.frame = CGRectMake(120, 288, 80, 120);
}
[self.view addSubview:self.countDownAnimationImage];
[UIView animateWithDuration:.8
delay:0
options:UIViewAnimationCurveEaseIn
animations:^{
self.countDownAnimationImage.transform = CGAffineTransformScale(self.countDownAnimationImage.transform, 1.5, 1.5);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:.5
delay:0
options:UIViewAnimationCurveEaseIn
animations:^{
self.countDownAnimationImage.alpha = 0;
}
completion:^(BOOL finished)
{
self.countDownAnimationImage.alpha = 1;
self.countDownAnimationImage.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"2" ofType:@"png"]];
self.countDownAnimationImage.transform = CGAffineTransformScale(self.countDownAnimationImage.transform, .66666667, .6666667);
[UIView animateWithDuration:.8
delay:0
options:UIViewAnimationCurveEaseIn
animations:^{
self.countDownAnimationImage.transform = CGAffineTransformScale(self.countDownAnimationImage.transform, 1.5, 1.5);
self.countDownAnimationImage.alpha = 1;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:.5
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
self.countDownAnimationImage.alpha = 0;
}
completion:^(BOOL finished) {
self.countDownAnimationImage.alpha = 1;
self.countDownAnimationImage.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1" ofType:@"png"]];
self.countDownAnimationImage.transform = CGAffineTransformScale(self.countDownAnimationImage.transform, .66666667, .6666667);
[UIView animateWithDuration:.8
delay:0
options:UIViewAnimationCurveEaseIn
animations:^{
self.countDownAnimationImage.transform = CGAffineTransformScale(self.countDownAnimationImage.transform, 1.5, 1.5);
self.countDownAnimationImage.alpha = 1;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:.5
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
self.countDownAnimationImage.alpha = 0;
}
completion:^(BOOL finished) {
[self.countDownAnimationImage removeFromSuperview];
}];
}];
}];
}];
}];
} ];
This is an example of a start animation that shows 3-2-1
I have more animations, but all are not as complex. I noticed that my app crashes on the ipad due to memory issues, and ran instruments.
It is not showing any leaks, but the allocation heap size is continuously increasing. After a heapshot analysis, I noticed that most of the memory was being consumed by:
VM: CoreAnimation
VM: ImageIO_PNG_Data
I tried looking at the stack trace, and am unable to figure out where exactly am I generating this abandoned memory.
Another example of the kind of animation I am using:
UIImageView *animationImage;
if([[UIScreen mainScreen]bounds].size.height == 568)
{
animationImage = [[UIImageView alloc]initWithFrame:CGRectMake(24, 250, 150, 80)];
}
else if([[UIScreen mainScreen]bounds].size.height == 480)
{
animationImage = [[UIImageView alloc]initWithFrame:CGRectMake(24, 200, 150, 80)];
}
else
{
animationImage = [[UIImageView alloc]initWithFrame:CGRectMake(184, 511, 218, 118)];
}
CGRect frame = animationImage.frame;
frame.size.height*=1.8;
frame.size.width*=1.8;
[animationImage setFrame:frame];
animationImage.image =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]];
animationImage.alpha = 0;
[self.view addSubview:animationImage];
[UIView animateWithDuration:.5
delay:0
options:UIViewAnimationCurveEaseIn
animations:^{
animationImage.alpha=1;
[animationImage setFrame:frame];
}
completion:^(BOOL finished) {
[UIView animateWithDuration:1.5
delay:.6
options:UIViewAnimationCurveEaseOut
animations:^{
animationImage.alpha=0;
CGRect frame = animationImage.frame;
if([[UIScreen mainScreen]bounds].size.height > 568)
{
frame.origin.y-=210;
}
else
{
frame.origin.y-=90;
}
[animationImage setFrame:frame];
}
completion:^(BOOL finished) {
[animationImage removeFromSuperview];
}];
}];