1

iOSプログラミングの学習を始めたばかりです。

アプリケーションの起動時にモーダル ウィンドウを特定のサイズで表示したいと考えています。だから、私のView Controllerで、このコードを書きました。

-(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)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 に答える