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

标签 ios objective-c xcode uiimageview uianimation

我的 ImageView 动画有问题。在我看来,有超过 10 个 View ,每个 View 都通过其标签值进行标识,并且我有 UIImageViewUIButton。当点击按钮时, View 的特定图像必须被动画化。如果有任何其他图像处于动画状态,则必须停止它。这是我的代码:

-(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 个以上按钮时,我的应用程序崩溃并出现内存警告。

最佳答案

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

关于ios - UIImageView动画开始并出现内存不足警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15066795/

相关文章:

ios - 事件指示器不会出现在 swift 4 上

ios - SDWebImage 库在 swift 3 Xcode 8.0 中出现错误

objective-c - 删除 Pod 会引发错误 : dyld: Library not loaded:

ios - Xcode 奇怪的随机错误不会消失

Titanium Studio 中未显示 iOS 模拟器

ios - Storyboard中的标签没有采用正确的本地化值

ios - 是否可以在 Swift 中自动注入(inject)异常处理代码?

ios - iphone 应用程序中的异步声音

ios - 1080p AVCaptureSession

objective-c - 调试 EXC_BAD_ACCESS