2017-02-15 6 views
1

Можно ли программно установить viewController на UIView? Я хочу сделать UIView, который всегда покрывает 50% высоты экрана и добавляет ViewController по этому view после его инициализации. Я не могу найти способ. Псевдокод:Установить ViewController on UIView программно

let view = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height UIScreen.main.bounds.height * 0.5) 

//Can't seem to find a method that does exactly this: 
view.setViewController(.......) 
+0

вид.setViewController (.......) в этом месте использовать view.addsubview (вашеVCname.view) –

+0

@ OleAndré Итак, у вас есть контроллер просмотра, 50% которого покрыты UIView, который обрабатывается с помощью другого контроллера представления? – Florensvb

+0

Связанный http://stackoverflow.com/a/42110439/6433023 для добавления ViewController in view –

ответ

0

Вставьте yourAnotherVC.view как подтаблица к yourview

var MenuView: AnotherViewController? = (self.storyboard?.instantiateViewController(withIdentifier: "NewsView") as? AnotherViewController) 
    self.addChildViewController(MenuView) 
    MenuView?.didMove(toParentViewController: self) 
    MenuView?.view?.frame = CGRect(x: CGFloat(0.0), y: CGFloat(self.containerView.frame.size.height), width: CGFloat(self.containerView.frame.size.width), height: CGFloat(self.containerView.frame.size.height)) 
    yourview.insertSubview(MenuView?.view, belowSubview: self.bottomMenuView) 

    //Show presentation logic here forward i mean show Anotherviewvc bottom to top or top to bottom 
0

Я спрячусь и показать взгляды вместо переключения из всего UIViews так больше никаких ответов не необходимый

# Закрыть
0
// Add Child View Controller from your MainVC 
    addChildViewController(viewController) //your 2nd VC 

    // Add Child View as Subview 
    view.addSubview(viewController.view) 

    // Configure Child View 
    viewController.view.frame = view.bounds //here you make it 50% of height! 
    viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

    // Notify Child View Controller 
    viewController.didMove(toParentViewController: self) 
0

Вы можете добавить контейнерный вид, в котором используется собственный UIViewController. Просто перетащите его из библиотеки объектов, и вы хорошо пойдете.

Смежные вопросы