iPad custom size of modal view controller

前端 未结 13 1970
挽巷
挽巷 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 08:53

    The approaches described above need to be tweaked for iOS7:

    // set desired bounds, then call -presentFromViewController:
    
    @implementation PresentedViewController
    {
        CGRect _presentationBounds;
    }
    
    - (void)presentFromViewController:(UIViewController *)viewController
    {
        self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        self.modalPresentationStyle = UIModalPresentationFormSheet;
    
        _presentationBounds = self.view.bounds;
    
        [viewController presentViewController:self animated:YES completion:nil];
    }
    
    - (void)viewWillLayoutSubviews
    {
        [super viewWillLayoutSubviews];
    
        if (!CGRectIsEmpty(_presentationBounds))
        {
            self.view.superview.bounds = _presentationBounds;
            _presentationBounds = CGRectZero;
        }
    }
    

    (This code also works on iOS6.)

提交回复
热议问题