0

我正在显示一个错误的登录屏幕,例如:

_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:.

我怎样才能让这个时间工作?

4

1 回答 1

1

您应该使用viewDidAppear控制器的方法,该方法将在视图显示时调用。

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

请小心,viewDidAppear因为每当显示您的视图时都会调用它。这意味着如果您的控制器呈现一个模态控制器,然后将其关闭,则将再次调用viewWillAppearandviewDidAppear方法。

于 2011-06-09T23:19:17.467 回答