【发布时间】:2016-05-30 09:32:32
【问题描述】:
我试图在无限循环中显示一个带有两个不断变化的字符串(如横幅)的间歇性标签。 第一个标签应该淡入。之后它应该淡出并让第二个标签做同样的事情。然后无限或长时间重复该序列。 标签位于 UITableView 的子类中。
到目前为止我已经试过了:
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
// Inside a cell an at its own section of the tableview
cell.label1.alpha = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationRepeatCount:INFINITY];
[cell.label1 setAlpha:0];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView commitAnimations];
cell.label2.alpha = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationRepeatCount:INFINITY];
[cell.label1 setAlpha:0];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView commitAnimations];
...
}
此代码运行良好,但效果不明显,因为 label1 的淡入与 label2 的淡出交叉,这很奇怪。 那么,我怎样才能在两个动画之间打断,以便清楚地看到褪色的标签呢?
【问题讨论】:
标签: ios objective-c uitableview