【发布时间】:2013-03-28 23:14:37
【问题描述】:
我正在使用 [UIView animateWithDuration... ] 来为我的应用程序的每个页面显示文本。每个页面都有自己的文本。我正在滑动以在页面之间导航。我正在使用 1 秒溶解效果让文本在页面显示后淡入。
问题出在:如果我在那 1 秒内滑动(在此期间文本淡入),动画将在下一页出现时完成,并且 2 个文本将重叠(上一个和当前)。
我想实施的解决方案是,如果我在动画发生期间碰巧滑动,则中断动画。我就是不能让它发生。 [self.view.layer removeAllAnimations];对我不起作用。
这是我的动画代码:
- (void) replaceContent: (UITextView *) theCurrentContent withContent: (UITextView *) theReplacementContent {
theReplacementContent.alpha = 0.0;
[self.view addSubview: theReplacementContent];
theReplacementContent.alpha = 0.0;
[UITextView animateWithDuration: 1.0
delay: 0.0
options: UIViewAnimationOptionTransitionCrossDissolve
animations: ^{
theCurrentContent.alpha = 0.0;
theReplacementContent.alpha = 1.0;
}
completion: ^(BOOL finished){
[theCurrentContent removeFromSuperview];
self.currentContent = theReplacementContent;
[self.view bringSubviewToFront:theReplacementContent];
}];
}
你们知道如何进行这项工作吗?你知道解决这个问题的其他方法吗?
【问题讨论】:
-
Cancel a UIView animation? 的可能重复项
-
您是否尝试将
removeAllAnimations发送到theCurrentContent.layer和theReplacementContent.layer? -
@matt,虽然有点不同