PresentViewController a non full screen UIViewController with UINavigationController in it

社会主义新天地 提交于 2020-01-16 00:49:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!