iPad custom size of modal view controller

前端 未结 13 1974
挽巷
挽巷 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:55

    The best way to do this is to change the bounds property on the superview of the view being presented inside the formsheet. When you present a view modally, the presented view is embedded inside another view.

    You should set the bounds property of the superview to the same rect as the view's bounds. First add a private ivar in your class:

    @implementation MySpecialFormsheet {
        CGRect _realBounds;
    } 
    

    It's best to do this in viewWillAppear:. Add the following code to the view controller that is being presented modally:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        self.view.superview.bounds = _realBounds;
    }
    

    You need to cache _realBounds in your viewDidLoad method:

    - (void)viewDidLoad {
        _realBounds = self.view.bounds;
        [super viewDidLoad];
    }
    

提交回复
热议问题