2011-06-09 75 views
0

我顯示的登錄屏幕出現錯誤,如:如何在presentModalViewController完成滑動後動畫?

_loginViewController.error = error; 
[_navigationController presentModalController: _loginViewController 
            animated: YES]; 

在LoginViewController,我想錯誤消息滑動到屏幕上是這樣的:

- (void)showErrorAnimated: (BOOL)animated; 
{ 
    _errorLabel.text = [_error localizedDescription]; 

    [UIView beginAnimations: @"showError" 
        context: NULL]; 
    CGRect frame = [_errorView frame]; 
    frame.origin.y = 0; // starts at -frame.size.height 
    [_errorView setFrame: frame]; 
    [UIView commitAnimations]; 
} 

但我不知道如何調用它來匹配視圖控制器的時序完成它滑動到由presentModalController:animated:開始的屏幕頂部。

我該如何獲得此計時工作?

回答

1

您應該使用控制器的viewDidAppear方法,該方法將被稱爲顯示視圖的時間。

http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW17

只是要小心viewDidAppear,因爲每當看到您視圖的叫法。這意味着如果您的控制器提供了一個模態控制器,然後將其解除,將再次調用viewWillAppearviewDidAppear方法。

+0

我正在玩這個,但除了重新顯示皺紋,它需要我使用'[UIView setAnimationDelay:]'來延遲動畫一些神奇的,無證的時間。我真的希望避免這種情況。 – 2011-06-09 23:23:41

+0

哦。我可能完全錯誤地推遲它。 (不要打擾檢查,我這樣做。) – 2011-06-09 23:26:43

+1

實際上,如果你編碼到ios 4,你應該使用它提供的方法,比如'animateWithDuration:animations:'http://developer.apple.com/ library/ios/documentation/uikit/reference/uiview_class/UIView/UIView.html#// apple_ref/doc/uid/TP40006816-CH3-SW111 – 2011-06-09 23:26:56