问题
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.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/17793459/presentviewcontroller-a-non-full-screen-uiviewcontroller-with-uinavigationcontro