vebqaq
Last Updated: February 25, 2016
·
12.15K
· juwe
1009630 10201943708167022 853443663 o

Resizing a view presented modally (iPad)

If you have tried this in the past maybe you finished in a dead end, but it's easier than yo thought.

This is the code to present a view controller modally:

UIViewController *myLOLViewController = [[UIViewController alloc] init]
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myLOLViewController];
[navigationController setModalPresentationStyle:UIModalPresentationFormSheet];

[self presentModalViewController:navigationController animated:YES];

The logic says that we have to try to resize the Modal before it's presented, so, i tried a lot of ways to do it but no one worked.

The trick is to resize the modal view "after" is presented, this is the full code:

UIViewController *myLOLViewController = [[UIViewController alloc] init]
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myLOLViewController];
[navigationController setModalPresentationStyle:UIModalPresentationFormSheet];

[self presentModalViewController:navigationController animated:YES];

navigationController.view.superview.frame = CGRectMake(0, 0, 600, 100);
navigationController.view.superview.center = self.view.center;

After all you just need to setCenter because it has changed after the resize. Obviously this works just for iPad; in iPhone the modally way to present views is a little bit different because of the space.

Say Thanks
Respond

4 Responses
Add your response

9805
2c7e413

I added galleryModalViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; to center, else no move to x or y

over 1 year ago ·
11649
3b2ed2556612bd9866936fe62efcaecc

@paulomcnally, nice job! You found an excellent solution for iOS7. Complete code here for those who are interested.

UIViewController *viewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:navigationController animated:YES completion:nil];
navigationController.view.superview.frame = CGRectMake(0, 0, 800, 544);
navigationController.view.superview.center = self.view.center;

over 1 year ago ·
15507

This doesn't seem to be working for me. I am doing the following, but the size is completely ignored. Does it have to do with the fact that I am loading my view from a nib?

  • (void)swipedUp:(id)sender {
    NSLog(@"Swiped up");
    paletteViewController *viewController = [[paletteViewController alloc] initWithNibName:@"paletteViewController" bundle:nil];

    viewController.delegate = self;
    [ viewController updateSelectedColor:self.drawView.selectedColor];
    [ viewController setSize:(ushort)self.drawView.selectedSize];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
    navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
    navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:navigationController animated:YES completion:nil];
    navigationController.view.superview.frame = CGRectMake(0, 0, 480, 280);
    navigationController.view.superview.center = self.view.center;
    }

over 1 year ago ·
18689
0 9g8ujtya1togzrxgn b1jipmphvjzvognin1jisauladoadcsxk8b jhgmsgnt0ac3ct9k1 rwex

In IOS 8 Frame setting is not working , when changing the orientation. For the Presentation Style "Form Sheet".

over 1 year ago ·