我需要動畫UIimageview,當我開始動畫它發生很長時間後,我發現內存泄漏的地方在各種圖像視圖的連續動畫的時間。我需要做的就是在滾動視圖中有n個UIviews,每個視圖都有一個自定義按鈕。選擇該按鈕時的動畫時,如果動畫是在過程中如果用戶點擊按鈕,該動畫將繼續下去,它不需要重新開始UIImageview動畫開始使用for-in循環和動畫延遲
這裏是我的代碼
for (int i=0; i<AlphabetArray.count; i++) {
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 200)];
view.backgroundColor=[UIColor grayColor];
view.tag=i+1;
[self.scrollView addSubview:view];
UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(200, 50, 400, 400)];
[image setImage:[[animationArray objectAtIndex:i]objectAtIndex:0]];
image.tag=i+1;
[view addSubview:image];
UIButton *animatebutton=[[UIButton alloc]initWithFrame:CGRectMake(200, 50, 336, 310)];
animatebutton.tag=i+1;
[animatebutton addTarget:self action:@selector(makeAnimation:) forControlEvents:UIControlEventTouchUpInside];
//[animatebutton setImage:[UIImage imageNamed:@"NewtDance_mov_0.png"] forState:UIControlStateNormal];
[view addSubview:animatebutton];
}
-(void)makeAnimation:(UIImageView *)sender {
UIView *tagView=(UIView *)[self.view viewWithTag:sender.tag];
for (UIImageView * imageview in [tagView subviews]) {
NSLog(@"Yes %d",imageview.tag);
if ([imageview isKindOfClass:[UIImageView class]]) {
if ([imageview isAnimating]) {
NSLog(@"Animation Happens");
}
else{
imageview.animationDuration=3.0;
imageview.animationImages=[animationArray objectAtIndex:sender.tag-1];
imageview.animationRepeatCount=2;
imageview.tag=sender.tag;
[imageview startAnimating];
}
}
}
NSLog(@"OK");
}
有了這個代碼我可以達到我的要求。但動畫開始時間很晚,因爲使用了for-in循環
確保你的動畫是完美的。然後減少動畫持續時間並檢查它與斷點也。 – Suresh 2013-02-22 10:59:00
@Suresh我試圖減少動畫的持續時間仍然面臨相同 – 2013-02-22 11:06:04
你檢查斷點?它實際上是什麼?你的動畫是完美的嗎? – Suresh 2013-02-22 11:07:55