繁体   English   中英

UIImageView动画开始并且出现内存不足警告

[英]UIImageView animation starts and low memory warning occurs

我的ImageView动画有问题。 在我的视图中,有10多个视图,每个视图都通过其标签值进行标识,并且我有UIImageViewUIButton 当点击一个按钮时,必须对该视图的特定图像进行动画处理。 如果还有其他动画图像,则必须停止。 这是我的代码:

-(void)makeAnimation:(UIButton *)sender {

UIView *tagView=(UIView *)[self.view viewWithTag:sender.tag];
UIView *next=nil;
UIView *previous=nil;


NSLog(@"%d",sender.tag);
for (UIImageView * imageview in [tagView subviews]) {
     if ([imageview isKindOfClass:[UIImageView class]]) {

        if ([imageview isAnimating]) {
            NSLog(@"Animation Happens");

        }

        else{

            imageview.animationDuration=2.0;

            imageview.animationImages=[animationArray objectAtIndex:sender.tag-1];
            imageview.animationRepeatCount=2;
            imageview.tag=sender.tag;
            [imageview startAnimating];
        }
    }

}
   next=(UIView*)[self.view viewWithTag:sender.tag+1];
    previous=(UIView*)[self.view viewWithTag:sender.tag-1];
    NSLog(@"NOT IDEA");

    [self previousview:previous nextview:next];
 }

-(void)previousview:(UIView *)previous nextview:(UIView*)next
{
for (UIImageView * imageview in [previous subviews]) {

    if ([imageview isKindOfClass:[UIImageView class]]) {

        [imageview stopAnimating];
        NSLog(@"PRREVIOUS");

              }

}

for (UIImageView * imageview in [next subviews]) {

    if ([imageview isKindOfClass:[UIImageView class]]) {

        [imageview stopAnimating];
        NSLog(@"NEXT");

     }
   }
}

现在我的问题是,当我一个接一个地选择四个以上的按钮时,我的应用程序崩溃并发出内存警告。

在运行时使用配置文件查找泄漏的确切位置,然后使用@autorelease {}手动处理内存,如下所示。

-(void)makeAnimation:(UIButton *)sender {
@autorelease{
UIView *tagView=(UIView *)[self.view viewWithTag:sender.tag];
UIView *next=nil;
UIView *previous=nil;


NSLog(@"%d",sender.tag);
for (UIImageView * imageview in [tagView subviews]) {
     if ([imageview isKindOfClass:[UIImageView class]]) {

        if ([imageview isAnimating]) {
            NSLog(@"Animation Happens");

        }

        else{

            imageview.animationDuration=2.0;

            imageview.animationImages=[animationArray objectAtIndex:sender.tag-1];
            imageview.animationRepeatCount=2;
            imageview.tag=sender.tag;
            [imageview startAnimating];
        }
    }

}
   next=(UIView*)[self.view viewWithTag:sender.tag+1];
    previous=(UIView*)[self.view viewWithTag:sender.tag-1];
    NSLog(@"NOT IDEA");

    [self previousview:previous nextview:next];
}
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM