iPad custom size of modal view controller

前端 未结 13 1980
挽巷
挽巷 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条回答
  •  Happy的楠姐
    2020-12-07 08:59

    All these answers will not work on ios8 SDK.

    This will work:

    AboutViewController * _aboutViewController = [[AboutViewController alloc] init];
        _aboutViewController.modalPresentationStyle = UIModalPresentationFormSheet;
        if(IS_IOS8)
        {
            _aboutViewController.preferredContentSize = CGSizeMake(300, 300);
        }
        [self presentViewController:_aboutViewController animated:YES completion:nil];
    

    In AboutViewController.m

    - (void)viewWillLayoutSubviews{
        [super viewWillLayoutSubviews];
    
        if(!IS_IOS8)
        {
            self.view.superview.bounds = CGRectMake(0, 0, 300, 300);
        }
    }
    

    IS_IOS8

    #define IS_IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8)
    

    In iOS 8 you can also use UIPresentationController which gives you more customization options.

提交回复
热议问题