我有一个水平表视图,想要每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];
随着我的意识,图像渐渐消失,我看到第二个图像滚动没有淡入淡出动画
答案 0 :(得分: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;
}];
}];