在tableview

时间:2016-05-30 09:32:32

标签: ios objective-c uitableview

我试图在无限循环中显示带有两个变化字符串(如横幅)的间歇标签。 第一个标签应该淡入。之后它应该淡出并让第二个标签做同样的事情。然后无限地或长时间重复序列。 标签位于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并且很奇怪。 那么,我如何在两个动画之间休息一下,清楚地看到褪色标签?

1 个答案:

答案 0 :(得分:0)

感谢@ Paulw11的回答,现在它运行正常,这是我的代码,包含更改:

cell.label2.alpha = 0;
            cell.label1.alpha = 1;

            [UIView animateKeyframesWithDuration:15 delay:0.0 options:0 animations:^{
                [UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.25 animations:^{
                    cell.label1.alpha = 0;
                    cell.label2.alpha = 0;
                    [self.view layoutIfNeeded];
                }];
                [UIView addKeyframeWithRelativeStartTime:0.25 relativeDuration:0.25 animations:^{
                    cell.label1.alpha = 0;
                    cell.label2.alpha = 1;
                    [self.view layoutIfNeeded];
                }];
                [UIView addKeyframeWithRelativeStartTime:0.50 relativeDuration:0.25 animations:^{
                    cell.label1.alpha = 0;
                    cell.label2.alpha = 0;
                    [self.view layoutIfNeeded];
                }];
                [UIView addKeyframeWithRelativeStartTime:0.75 relativeDuration:0.25 animations:^{
                    cell.label1.alpha = 1;
                    cell.label2.alpha = 0;
                    [self.view layoutIfNeeded];
                }];

                [UIView setAnimationRepeatCount: 200];


            } completion:nil];