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.

Mazen Kasser
  • 3,559
  • 2
  • 25
  • 35

5 Answers5

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...

Mazen Kasser
  • 3,559
  • 2
  • 25
  • 35
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.

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
  • 2
    It shows black background when I present the viewController. And I think UIModalPresentationFormSheet is available on iPad only! – Mazen Kasser Dec 05 '13 at 20:17
  • 1
    After iOS 8 you can do viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext; – Mazen Kasser Jan 20 '16 at 23:07
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

EhTd
  • 3,260
  • 4
  • 19
  • 18
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.

Alexander Perechnev
  • 2,797
  • 3
  • 21
  • 35
  • 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 iPhone – Mazen Kasser Dec 05 '13 at 23:18
  • @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. – Alexander Perechnev Dec 05 '13 at 23:50
  • 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 up – Mazen Kasser Dec 06 '13 at 01:53
  • @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. – Alexander Perechnev Dec 06 '13 at 02:09
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.

Wubao Li
  • 1,728
  • 10
  • 13
  • 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 anyways – Mazen Kasser Dec 05 '13 at 23:47