Presenting a modal view controller without covering the current view on iPhone
Asked Answered
I

5

9

enter image description here

I have been trying to add view container with leaving 20px space from the sides. But it seems not the proper way of doing it...

// ADD CHILD VIEW CONTROLLER
    [parentViewController addChildViewController:childViewController];
    [parentViewController.view addSubview:childViewController.view];
    [childViewController didMoveToParentViewController:parentViewController];

// REMOVE THE CHILD VIEW CONTROLLER
    [childViewController willMoveToParentViewController:nil];
    [childViewController view] removeFromSuperview];
    [childViewController removeFromParentViewController];

UPDATE I have figured it out by using this MZFormSheetController "https://github.com/m1entus/MZFormSheetController" Form presentation with cool view transitions.

Impale answered 5/12, 2013 at 2:36 Comment(1)
Thanks for mentioning "MZFormSheetController" !Unpen
I
6

Use MZFormSheetController "https://github.com/m1entus/MZFormSheetController" Form presentation with cool view transitions. Or, iOS 8 and above, you can use viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext; Good luck, let me know if you want a full snippet...

Impale answered 30/4, 2014 at 22:35 Comment(0)
T
4

You can try Something like,

DetailViewController *viewController= [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
viewController.modalPresentationStyle=UIModalPresentationFormSheet;
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentViewController:viewController animated:YES completion:^{
    viewController.view.superview.frame = CGRectMake(0, 0, 310, 500);
    viewController.view.superview.center = self.view.center;
}];

Set superview.frame and modalTransitionStyle according to you.

Tsar answered 5/12, 2013 at 5:24 Comment(2)
It shows black background when I present the viewController. And I think UIModalPresentationFormSheet is available on iPad only!Impale
After iOS 8 you can do viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;Impale
T
1

The better way is to have your own controller and view.

On the main controller use the present view controller.

[self presentViewController:myController animated:YES completion:nil];

On the viewDidLoad adjust myController frame.

CGRect newFrame = self.view.frame;
newFame.size.width -= 40;
newFame.size.height -= 40;
newFrame.origin.x = 20;
newFrame.origin.y = 20;
self.view.frame = newFrame

Adding as childViewController is for view controller containment, when you want a single controller with multiples views, each with its own controller.

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html

Tabbatha answered 5/12, 2013 at 20:18 Comment(0)
S
1

You're on a right way. But you have to add container view permanently on a storyboard, then you can just show/hide it by setHidden: method.

Also you can show second controller animated by this method.

Solidary answered 5/12, 2013 at 20:29 Comment(4)
you are right but it won't be as proper as this app has it... I am sure there is code somewhere for presenting UIModalPresentationFormSheet on iPhoneImpale
@MazenKasser UIModalPresentationFormSheet is working only on iPad. You have to read UI guidelines for iOS, an book written by Apple. I think you didn't yet. Even if you find such method, Apple will restrict you app, because it is not accomplish wish UI guidelines.Solidary
everything is possible, there are heaps of 3rd party libraries that customise Apples' APIs. Relax Apple won't reject the App for such thing... btw I have read that book since 2009, son you should catch upImpale
@MazenKasser we was talking about UIModalPresentationFormSheet in iPhone, am i right? Relax father I've just said that Apple restricts app event if you find a way to use UIModalPresentationFormSheet at iPhone. There were no words about 3rd-party implementations.Solidary
E
0
  1. On iPhone and iPod touch, the presented view is always full screen. So, it can't be presenting a non-full screen view controller.

  2. Don't presenting the view controller, add the view controller's view as a subview to the parent view controller. So, you can control the appearance, even the shadow layer under it.

Excepting answered 5/12, 2013 at 5:35 Comment(1)
the concept is correct but the code doesn't work as expected. First the child view goes under the navigationController of the root view controller, so I had to hide it and add a navigation bar... I think I should stick to my own code for now... thanks anywaysImpale

© 2022 - 2024 — McMap. All rights reserved.