スライダーを使用して一連のアニメーションをトリガーする際に問題があります。コードは次のとおりです。
-(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
フローは問題なく動作します。