我刚刚开始学习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];
}
使用此代码,模态窗口会显示,但是,它显示的大小适合屏幕尺寸。
我希望我的模态窗口显示我设置的大小。
我怎样才能让它发挥作用?
非常感谢你!!
答案 0 :(得分: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);
答案 1 :(得分: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];
}
希望这个帮助