1

I am trying to figure out if there is a way to present a UIViewController which is not full screen. It should be of custom size & not what can be achieved using modalPresentationStyle.

I wanted to create a view like the native Twitter/Facebook sharing sheet's size with UINavigationController so that I can push/pop more UIViewControllers. It should work for iPhone and iPad.

msk
  • 8,885
  • 6
  • 41
  • 72

2 Answers2

2

You can use View Controller Containment to do this. See "Implementing A Container View Controller" at http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html for more info. Basically you just need to call addChildViewController: before adding the child's view to your view, and removeFromParentViewController: before removing it.

jsd
  • 7,673
  • 5
  • 27
  • 47
0

What I did was roughly:

override func viewDidLoad() {
    super.viewDidLoad()

    self.edgesForExtendedLayout = UIRectEdge.None // Otherwise the sub view might go under the parent's navigation bar

    let vc = MyPresentedViewController()
    self.addChildViewController(vc)
    self.view.addSubView(vc.view)
}

and it seemed to work ok.

mllm
  • 17,068
  • 15
  • 53
  • 64