0

ImageViewアニメーションに問題があります。私のビューには10を超えるビューがあり、各ビューはそのタグ値から識別されUIImageViewますUIButton。ボタンをタップすると、ビューの特定の画像をアニメーション化する必要があります。他の画像がアニメーション化されている場合は、停止する必要があります。これは私のコードです:

-(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つ以上のボタンを次々に選択すると、メモリ警告でアプリがクラッシュすることです。

4

1 に答える 1

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-02-25T12:58:32.627 に答える