Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 淡入/淡出2个标签无限循环在tableview中_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 淡入/淡出2个标签无限循环在tableview中

Ios 淡入/淡出2个标签无限循环在tableview中,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我试图在无限循环中显示一个带有两个变化字符串(如横幅)的间歇标签。 第一个标签应该淡入。之后,它应该淡出,让第二个标签做同样的事情。然后无限次或长时间重复该序列。 标签位于UITableView的子类内 到目前为止,我试过: - (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... // Inside a cell an a

我试图在无限循环中显示一个带有两个变化字符串(如横幅)的间歇标签。 第一个标签应该淡入。之后,它应该淡出,让第二个标签做同样的事情。然后无限次或长时间重复该序列。 标签位于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];

...
}
这段代码工作正常,但效果不清楚,因为淡入标签1与淡出标签2交叉,这很奇怪。
那么,我如何在两个动画之间休息一下,才能清楚地看到褪色的标签呢?

谢谢@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];

谢谢@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];
使用关键帧动画使用关键帧动画