簡體   English   中英

在彈出過渡到的視圖控制器之前,如何使單元格保持突出顯示狀態?

[英]How do you have a cell stay highlighted until you pop the view controller it transitions to?

許多應用程序都具有這種效果,您可以在其中單擊單元格,然后過渡到新的視圖控制器,然后在彈出該視圖控制器時返回到單元格,然后輕按以到達該單元格的單元格就會消失。 基本上,它只會在您返回視圖控制器時淡出,從而為您敲擊哪個單元格提供了一個非常漂亮的視覺隊列。

例如,它在Mail.app中可見。

我該怎么做呢? 看來我只能使它立即消失或根本不消失。

例如,您有兩個視圖控制器, ListViewController (表一)和DetailViewController

  • 在ListViewController.h中,添加一個參數: selectedIndexPath (NSIndexPath類型)。
  • 在ListViewController.m-> didSelectRowAtIndexPath ,將其值設置為當前indexPath

    selectedIndexPath = indexPath;

  • 現在,當您從DetailViewController單擊后退按鈕並返回ListViewController ,將從ListViewController調用viewWillAppear方法。

ListViewController.m-> viewWillAppear

if (selectedIndexPath != nil) {

   // 1. get the cell using cellForRowAtIndexPath method from selectedIndexPath position
   // 2. now you can set cell.contentView.alpha = 0
   // 3. write an animation block which will set alpha to 1 in particular time block, let say 1 sec.

    [cell.contentView setAlpha:0.0f];
    [UIView animateWithDuration:1
                          delay:1.0
                        options: UIViewAnimationCurveEaseOut // change option as per your requirement
                     animations:^{
                         [cell.contentView setAlpha:1.0f];
                     } 
                     completion:^(BOOL finished){
                         NSLog(@"Done!");
                     }];
}

根據您的要求更新動畫塊。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM