2013-02-25 44 views
0

我的ImageView动画有问题。在我看来,有超过10个视图,每个视图都从它的标记值&中标识出我有UIImageViewUIButton。当点击一个按钮时,该视图的特定图像必须动画化。如果任何其他图像动画,它必须停止。这是我的代码:UIImageView动画启动并发生低内存警告

-(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个按钮,一个又一个的我的应用程序崩溃与内存警告。

+0

启用乌尔应用ARC? – Ganapathy 2013-02-25 12:38:31

+0

@Ganapathy是... – 2013-02-25 12:44:36

回答

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]; 
} 
}