1

我刚开始学习ios编程。

我想在我的应用程序启动时以特定大小显示模式窗口。所以,在我的视图控制器中,我编写了这段代码。

-(void)viewDidAppear:(BOOL)animated{

    ModalViewController *modal;
    modal = [[ModalViewController alloc] init];
    modal.modalPresentationStyle = UIModalPresentationFormSheet;
    modal.view.frame = CGRectMake(0, 0, 100, 100);

    [self presentViewController:modal animated:YES completion:nil];
}

使用此代码,模态窗口会显示出来,但是,它会以适合屏幕大小的大小显示。

我希望我的模态窗口以我设置的大小显示。

我怎样才能让它工作?

非常感谢您提前!!

4

2 回答 2

0

你可以试试这个:

-(void)viewDidAppear:(BOOL)animated{

ModalViewController *modal=[[LoginViewController alloc] init];
modal.view.frame = CGRectMake(0, 0, self.view.frame.size.width , self.view.frame.size.height);
modal.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentViewController:modal animated:YES completion:nil];
}

希望这有帮助

于 2013-10-01T04:08:07.527 回答
0

尝试

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];   
    self.view.superview.bounds = CGRectMake(0, 0, <width>, <height>);
}

或者

ViewController.modalPresentationStyle = UIModalPresentationFormSheet;
ViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:ViewController animated:YES completion:nil];
ViewController.view.superview.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
ViewController.view.superview.frame = CGRectMake(
                                                                    // Calcuation based on landscape orientation (width=height) 
                                                                    ([UIScreen mainScreen].applicationFrame.size.height/2)-(320/2),// X
                                                                    ([UIScreen mainScreen].applicationFrame.size.width/2)-(320/2),// Y
                                                                    320,// Width
                                                                    320// Height
                                                                    );

或尝试用这个替换最后一行

ViewController.view.superview.bounds = CGRectMake(0, 0, 320, 320);
于 2013-10-01T03:30:38.473 回答