我试图逐个更改子视图的颜色,但所有视图的颜色都立即更改,即使我已将动画持续时间设置为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