0

我正在制作一个有很多动画和嵌套动画的应用程序。

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];


                                                                                                              }];

                                                                                         }];


                                                                    }];

                                               }];
                          }];

                     } ];

这是一个显示 3-2-1 的开始动画示例

我有更多动画,但都没有那么复杂。我注意到我的应用程序由于内存问题而在 ipad 上崩溃,并运行了仪器。

它没有显示任何泄漏,但分配堆大小不断增加。在进行了 heapshot 分析之后,我注意到大部分内存都被以下内容消耗了:

虚拟机:CoreAnimation

虚拟机:ImageIO_PNG_Data

我尝试查看堆栈跟踪,但无法弄清楚我到底在哪里生成了这个废弃的内存。

我正在使用的动画类型的另一个示例:

    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];

                                      }];
                 }];
4

0 回答 0