我試圖逐個更改子視圖的顏色,但所有視圖的顏色都立即更改,即使我已將動畫持續時間設置爲2秒。在UIView動畫中調用immediatly的完成塊
- (void)runAnimation
{
NSMutableArray *views = [[NSMutableArray alloc]init];
for (UIView *bubble in self.subviews)
{
if(bubble.tag == 2500)
[views addObject:bubble];
}
__weak PKCustomSlider *weak_self = self;
__block NSInteger currentView = 0;
self.animationBlock = ^{
[UIView animateWithDuration:2 animations:^{
NSLog(@"Animation block called again");
[views[currentView] setBackgroundColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:1]];
} completion:^(BOOL finished) {
currentView += 1;
if(!finished)
{
NSLog(@"Animation hasn't finished");
return;
}
if (currentView == views.count){
currentView = 0;
NSLog(@"Animation block ended");
}
else
{
weak_self.animationBlock();
NSLog(@"Animation block called again because views still available in the array");
}
}];
self.animationBlock();
}
你怎麼在日誌中看到了什麼? – jrturton 2014-10-29 15:48:49
我認爲如果視圖不是當前UIWindow的子視圖,則立即執行完成塊。 – 2014-10-29 15:51:44
@ianmacdonald絕對正確 – jrturton 2014-10-29 17:48:06