0

I have an issue with my ImageView animation. In my view there are more than 10 views and each view have are identified from its tag value & I have UIImageView and UIButton. when a button is tapped then that particular image of the view have to be animated. If any other images are animated it have to be stopped. This is my code:

-(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");

     }
   }
}

Now my issue is when I select more than 4 buttons one after another my app crashed with memory warning.

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97

1 Answers1

1

Find the exact location of leak using profile while running and use @autorelease{} to handle the memory manually Like this..

-(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];
}
 }
Ganapathy
  • 4,594
  • 5
  • 23
  • 41