1

I'm developing for iPad and I have the following problem:

I'm trying to show a modal with his own size and his own UINavigationController, I already done that, but when I present the modal with his UINavigationController, I get this:

Modal with UINavigationController

I want the UINavigationController to fit to modal size. I leave the code of how I'm presenting the modal:

- (void)createANewEvent:(id)sender { AddEditEventViewController *addEditEventViewController = [[(ScheduleViewController *)self.viewContainer storyboard] instantiateViewControllerWithIdentifier:@"AddEditEventViewControllerID"]; addEditEventViewController.modalPresentationStyle = UIModalPresentationFormSheet; addEditEventViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addEditEventViewController]; [self.viewContainer presentViewController:navigationController animated:YES completion:nil]; } 

How I resize the modal:

AddEditEventViewController.m // Resize the view - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; self.view.superview.bounds = CGRectMake(0, 0, 548, 768); self.view.superview.backgroundColor = [UIColor clearColor]; } 

Hope you can help me!

Thanks in advance! :)

3 Answers 3

2

A view should never modify its superview's size or position.

The problem is that you're setting modalPresentationStyle on the root view controller instead of the view controller you're presenting, navigationController.

  1. Delete:

    addEditEventViewController.modalPresentationStyle = UIModalPresentationFormSheet; addEditEventViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
  2. Delete the viewWillLayoutSubviews method you posted.

  3. Add:

    navigationController.modalPresentationStyle = UIModalPresentationFormSheet; navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
Sign up to request clarification or add additional context in comments.

6 Comments

I will try your code in a moment... but why I shouldn't modify the superview??
Because you should only modify down the view hierarchy, not up. It leads to erratic behavior and poorly designed code. A view should not know anything about how it's being presented, or any views that are outside of it - that's a job for a higher level object.
Ok, you got a point. Do you have any reference link that support your comment answer??
No, but I'm sure if you read books or articles on object oriented design patterns, you'll hear the same thing.
Yeah. @Jack Cox has just tell me the same. Thanks for the advice :)
|
1

I would sub-class UINavigationController and implement the method:

preferredContentSize

Something like

- (CGSize) perferredContentSize { return CGSizeMake(548,768); } 

That's all you should need to do to have properly resized modal views.

and have it return a CGSize structure with the size that you want the modal to be. This is the 'correct' way to do it per Apple documentation.

In conjunction, remove the viewWillLayoutSubviews method, that's just going to cause problems sometime in the future.

Comments

-2

After [self.viewContainer presentViewController....] add:

navigationController.view.superview.bounds = CGRectMake(0, 0, 548, 768); 

and get rid of your viewWillLayoutSubviews

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.