2011-11-03 16 views
4

我會實現,當你在我的應用程序請求的東西(如按下按鈕或任何),我想它會出現一個小的矩形,說「加載..」,當加載完成後,它會消失,並出現「向上滑動效應」。我做了一個簡單的模型來描述我想要達到的目標。你有什麼暗示給我嗎?謝謝。iPhone的加載視圖「幻燈片效果」

enter image description here

注:我不想拉刷新效果(加載視圖顯示沒有屏幕滾動,當你發送評論似乎爲例)

UPDATE:

我已經試過卷層雲代碼:

- (IBAction)displayLoadingScreen:(id)sender 
{ 
    NSLog(@"pressed"); 
    UIView *loadingView = [[UIView alloc] init]; 
    loadingView.frame = CGRectMake(0,-40,320,40); 
    [loadingView setBackgroundColor:[UIColor blueColor]]; 
    [self.view addSubview:loadingView]; 
    //animate in within some method called when loading starts 
    [UIView animateWithDuration:1.0 
        animations:^{ 
         loadingView.frame = CGRectMake(0,0,320,40); 
        } 
        completion:^(BOOL finished) { 
        }]; 
    for (int i = 0; i < 10000; i++) { 
     NSLog(@"%d", i); 
    } 
    //animate out within some method called when loading ends 
    [UIView animateWithDuration:1.0 
        animations:^{ 
         loadingView.frame = CGRectMake(0,-40,320,40); 
        } 
        completion:^(BOOL finished){ 


        }]; 
} 

爲什麼加載視圖在 for循環後滑動?如果你嘗試它,在打印for循環之前,執行完兩個動畫之後。想法?

更新2

- (void)stopLoading { 
    [UIView animateWithDuration:1.0 
        animations:^{ 
         loadingView.frame = CGRectMake(0,-40,320,40); 
        } 
        completion:^(BOOL finished){ 
        }]; 
} 

- (void)startLoading { 
    loadingView.frame = CGRectMake(0,-40,320,40); 
    [loadingView setBackgroundColor:[UIColor blueColor]]; 
    [self.view addSubview:loadingView]; 
    //animate in within some method called when loading starts 
    [UIView animateWithDuration:1.0 
        animations:^{ 
         loadingView.frame = CGRectMake(0,0,320,40); 
        } 
        completion:^(BOOL finished) { 
        }]; 
    sleep(5); 
    [self stopLoading]; 
} 

- (IBAction)displayLoadingScreen:(id)sender 
{ 
    NSLog(@"button pressed"); 
    [self startLoading]; 
} 
+0

嘗試閱讀'UIAnimation'類(並使用QuartzCore框架)。 – Raptor

+0

或者,如果您想使用滑動下來更新Facebook等功能,請考慮使用'EGOTableViewPullRefresh'。 – Raptor

回答

5
loadingView.frame = CGRectMake(0,-40,320,40); 
[loadingView setBackgroundColor:[UIColor blueColor]]; 
[self.view addSubview:loadingView]; 
//animate in within some method called when loading starts 
[UIView animateWithDuration:1.0 
       animations:^{ 
        loadingView.frame = CGRectMake(0,0,320,40); 
       } 
       completion:^(BOOL finished){ 


       }]; 
//animate out within some method called when loading ends 
[UIView animateWithDuration:1.0 
       animations:^{ 
        loadingView.frame = CGRectMake(0,-40,320,40); 
       } 
       completion:^(BOOL finished){ 


       }]; 
+0

結帳我的更新請。謝謝。 –

+1

在我的回答中,我告訴過你要將這些動畫放在單獨的方法中,一個在加載開始時被調用,另一個在加載結束時被調用。循環在動畫完成之前執行,因爲動畫需要1秒的執行時間,這是在其他代碼繼續時完成的。因此,回顧一下 - 不要在同一個方法中同時使用動畫。當裝載實際上應該開始時調用一個,當裝載實際完成時調用另一個,並且你會很好。 –

+0

感謝您的耐心,但我沒有爲我工作。看到我的新更新。爲什麼執行的第一條語句是「睡眠」,而不是我在動畫中的第一張幻燈片? –

1

我會做的就是在你與你想裝設計其他意見前加上一個視圖。

然後,當加載完成(使用的通知或只是調用視圖的功能),與那種動畫往上:

[UIView animateWithDuration:0.3 
           delay:0 
          options:UIViewAnimationOptionAllowUserInteraction 
         animations:^{ 
          //change the frame to make the view go out of the screen 
         } 
         completion:^(BOOL finished){ 
          //do whatever you want with the view (release it for instance) 
         }]; 
0

你可以用別的微調的幫助下做你只需要查看和設置動畫的座標,當你點擊任何對象時,它將在你的視圖中彈出,加載完成後你必須爲你的彈出視圖跳躍設置' - '座標(框架)。 ...