在启动时显示模态登录 - 通过UITableView

时间:2012-10-10 17:23:32

标签: ios cocoa-touch ipad

我想在启动时在屏幕中央显示一个登录模式,但是我得到一个空白背景,模态忽略了我的位置代码。

我有一个基于UITableView的iOS应用程序。当用户首次打开应用程序时,我想在屏幕中央显示一个模态登录窗口。在我的主视图controller的viewDidLoad中,我设置了UITableViewController使用的所有数据。然后我用以下方法调用我的模态窗口(为了示例目的略微改变):

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    TenKeyPad *passwordEntry = [[[TenKeyPad alloc] initWithValues:@"" PasswordEntry:TRUE] autorelease];
    passwordEntry.delegate = self;

    passwordEntry.modalPresentationStyle = UIModalPresentationFormSheet;
    passwordEntry.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    passwordEntry.view.superview.frame = CGRectMake(0,0,320, 460); // iphone screen is 320 x 480 (-20px that would normally be the toolbar)
    passwordEntry.view.superview.center = CGPointMake(768/2, 1024/2 + 10);

    [self presentViewController:passwordEntry animated:NO completion:nil];

    [passwordEntry release];
} 

我希望模式密码窗口显示在表格视图上,但相反,它显示在显示屏的左上角,背景为深灰色。但是,如果我稍后在应用程序中使用完全相同的代码调用此模式,则其行为与预期/期望相同。 加载模态的正确方法或时间是什么,以便显示在我的tableView上?

截图

故障

Faulty login window

所需/预期

Desired/Expected login window

1 个答案:

答案 0 :(得分:1)

我也很难用这个功能。我还没有找到一种从一开始就设置模态大小的正确方法。我会尝试这样的事情:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    LoginViewController *controller = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    controller.modalPresentationStyle = UIModalPresentationFormSheet;
    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    [self presentViewController:controller animated:NO completion:^{
        // resize
        controller.view.superview.frame = CGRectMake(self.view.frame.size.width/2-160, self.view.frame.size.height/2-230, 320, 460);
    }];
}

这可以满足你的需要,但动画无法正常工作。

相关问题