2012-08-22 85 views
-5

我有一個水平表格視圖並且想要每5秒更換一次圖像。我想這樣的舊形象淡出,並在新的淡出改變淡入動畫圖像,所以我把這個方法:。當滾動水平表格視圖時淡入淡出動畫

self.slideTimer = [NSTimer scheduledTimerWithTimeInterval:5 
                target:self 
               selector:@selector(slideToNextImage) 
               userInfo:nil 
                repeats:YES]; 

這裏是我的slideToNextImage:

self.lastIndexPath = indexPath; 
[UIView beginAnimations:@"FadeAnimations" context:nil]; 
[UIView setAnimationDuration:2]; 
self.horizontalView.alpha = 0.1f; 
[self.horizontalView.tableView scrollToRowAtIndexPath:self.lastIndexPath 
     atScrollPosition:UITableViewScrollPositionMiddle 
       animated:NO]; 
[UIView commitAnimations]; 
[UIView beginAnimations:@"FadeAnimations" context:nil];  
[UIView setAnimationDuration:2]; 
self.horizontalView.alpha = 1.0f; 
[UIView commitAnimations]; 

隨着我的實現圖像變得太快,我看到第二個圖像滾動,沒有褪色動畫

+1

你可以給你想要做什麼,是什麼問題,一些更多的信息? – Sebrassi

+0

請做出一些截圖來指定你的要求。 – holex

+0

對不起,編輯我的帖子,希望這會有所幫助 – user801255

回答

3

第二個動畫開始時沒有等待第一個結束。

嘗試這樣的事情,而不是:

[UIView animateWithDuration:2.0 animations:^{ 
    self.horizontalView.alpha = 0.1f; 
    [self.horizontalView.tableView scrollToRowAtIndexPath:self.lastIndexPath 
             atScrollPosition:UITableViewScrollPositionMiddle 
               animated:NO]; 

} completion:^(BOOL finished) { 
    [UIView animateWithDuration:2 animations:^{ 
     self.horizontalView.alpha = 1.0f; 
    }]; 
}]; 
+0

謝謝,這工作,但動畫不平滑我看到一些滯後scrollToRowAtIndexPath:執行。是否有可能使它平滑? – user801255

+0

這段代碼可能不是導致動畫波濤洶涌的問題。否則你是否在同時吃掉處理能力/耗盡大量內存? – James

+0

所以滾動不應該是動畫?您可以在完成塊內移動scrollToRow方法調用在第二個動畫之前! – Sebrassi