How to resize modalViewController using UIModalPresentationPageSheet

I have a modal view controller that I am showing with a UIModalPresentationPageSheet. The problem is that its default size is too large for my content: so I want to resize the frame to adjust it to fit my content.

Does anyone know a way / trick to do this?

thank

+1
source share
3 answers

You cannot resize UIModalPresentationPageSheet because its size does not change.

0
source

, UIModalPresentationPageSheet. :

<!--The header file-->
@interface MyViewController: ViewController{
  //Used to store the bounds of the viewController
  CGRect realBounds;
}

<!--In the .m file-->

//viewDidLoad gets called before viewWillAppear, so we make our changes here
-(void)viewDidLoad{
    //Here you can modify the new frame as you like. Multiply the 
    //values or add/subtract to change the size of the viewController.
    CGRect newFrame = CGRectMake(self.view.frame.origin.x, 
                                 self.view.frame.origin.y,       
                                 self.view.frame.size.width, 
                                 self.view.frame.size.height); 

    [self.view setFrame:newFrame];

    //Now the bounds have changed so we save them to be used later on
    _realBounds = self.view.bounds;

    [super viewDidLoad];
}

//viewWillAppear gets called after viewDidLoad so we use the changes 
//implemented above here
-(void)viewWillAppear:(BOOL)animated{

    //UIModalpresentationPageSheet is the superview and we change 
    //its bounds here to match the UIViewController view bounds.
    [super viewWillAppear:animated];
    self.view.superview.bounds = realBounds;

}

UIModalPresentationPageSheet. . iOS 5.1.1 iOS 6 .

+6

This works to resize the view controller represented as UIModalPresentationFormSheet. I would try, I'm not sure if this will work or not:

navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navController animated:YES];
//these two lines are if you want to make your view smaller than the standard modal view controller size
navController.view.superview.frame = CGRectMake(0, 0, 200, 200);
navController.view.superview.center = self.view.center;
-1
source

All Articles