iPad custom size of modal view controller

前端 未结 13 1995
挽巷
挽巷 2020-12-07 08:11

I have a couple of modal view controllers of certain size. I\'m trying to avoid the use of custom views (creating full screen black translucent overlay over current view, ad

13条回答
  •  生来不讨喜
    2020-12-07 09:02

    Even I was struggling with the same issue for quite a while. After giving few tries from many of the answers given here I came up with a solution that worked for me pretty well.

    Here is the code while presenting the view controller.

        SomeViewController *sovcObj = [[SomeViewController alloc] initWithNibName:@"SyncOptionsViewController" bundle:nil];
    someObj.modalPresentationStyle = UIModalPresentationFormSheet;
    someObj.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:someObj animated:YES completion:nil];
    someObj.view.superview.bounds = CGRectMake(0, 0, 400, 400); // whatever width and height you want
    

    In the xib (if you are using one) in the 'Simulated Metrics' section select 'Freeform' size.

    Apart from this you need to write the below code in your presented view controller (i.e.., SomeViewController in this example)

    - (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 400, 400); // whatever width and height you want
    

    }

    This code also works for iOS 7 as well

提交回复
热议问题