2013-10-01 23 views
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]; 
} 

使用此代碼,模式窗口顯示,但它顯示與適合屏幕大小的大小。

我想我的模態窗口顯示與我設置的大小。

我該如何讓它工作?

非常感謝您提前!

回答

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); 
+0

謝謝你的支持!我複製上面的代碼並將其粘貼到我的視圖控制器中,但它沒有改變。我是否應該保留我的代碼,並將其添加到相同的視圖控制器中? – crzyonez777

+0

順便說一句,這個視圖控制器被添加到AppDelegate.m中的導航控制器。我不知道它是否重要。 – crzyonez777

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]; 
} 

希望得到這個幫助

+0

感謝您的支持!我試過你的代碼,但沒有奏效。這個視圖控制器添加到appDelegate.m中的導航控制器是否重要? – crzyonez777