我在使用滑块触发一系列动画时遇到问题,代码如下:
-(void)slideAlpha:(id)sender{
self.bigPhotoViewA.alpha = self.alphaSlider.value;
if (self.alphaSlider.value == 1){
[UIView animateWithDuration:1
animations:^{
self.alphaSlider.alpha = 0;
} completion:nil
];
[self performSelector:@selector(nextPhotoAnimation) withObject:self afterDelay:5.0 ];
}
}
-(void) nextPhotoAnimation{
self.alphaSlider.value = 0;
[UIView animateWithDuration:2
animations:^{
self.bigPhotoViewA.alpha = 0.0;
self.bigPhotoView.alpha = 0.0;
self.smallPhotoView.center = CGPointMake(startX, startY);
}
completion:^(BOOL finished) {
NSLog(@"Animation ended");
self.smallPhotoView.image = ((UIImage *)[smallImagesArray objectAtIndex:imageCount]);
}
];
}
因此,当滑块达到值 1 时,nextPhotoAnimation
会在延迟后启动。到目前为止,一切都很好。问题来了nextPhotoAnimation
。该animations
块运行正常,但每次调用该completion
块都会运行多次。nextPhotoAnimation
启动时NSLog
显示 6 到 9 次nextPhotoAnimation
,然后在 2 秒后在正确的时间再次显示。
我试图用更简单的代码来复制这个问题,并且animation
/completion
流工作得很好。