2016-05-30 49 views
1

我试图在无限循环中显示带有两个更改字符串(如横幅)的间歇标签。 第一个标签应该淡入。之后,它应该淡出,让第二个标签也一样。然后无限或长时间地重复这个序列。 该标签位于UITableView的子类中。淡入/淡出2标签桌面视图内的无限循环

我想这个至今:

- (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效果并不清楚,很是怪异。 那么,我该如何在两个动画之间做个休息,以清楚看到衰落标签?

+0

使用关键帧动画http://commandshift.co.uk/blog/2014/04/01 /停止嵌套动画块/ – Paulw11

回答

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