【问题标题】:UIImageView animation starts and low memory warning occursUIImageView 动画启动并出现内存不足警告
【发布时间】:2013-02-25 12:16:45
【问题描述】:

我的 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");

     }
   }
}

现在我的问题是当我一个接一个地选择超过 4 个按钮时,我的应用程序因内存警告而崩溃。

【问题讨论】:

  • 您的应用程序是否启用了 ARC?

标签: ios objective-c xcode uiimageview uianimation


【解决方案1】:

在运行时使用配置文件找到泄漏的确切位置并使用@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];
}
 }

【讨论】:

    猜你喜欢
    • 2013-03-05
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多