2016-05-30 12 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];