如何在其他UIViewController中设置UIViewController的位置和大小

时间:2019-01-02 05:07:29

标签: ios swift uiviewcontroller

我这样做是为了将ViewController(viewController)移至其他ViewController(mainMenuViewController):

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "subView")
    addChildViewController(controller)
    view.addSubview(controller.view)
    controller.view.frame.size.width = 375
    controller.view.frame.size.height = 198
    controller.didMove(toParentViewController: self)

viewController移至mainMenuViewController,但问题是我看不到其他诸如tableView,已添加到mainMenuViewController的按钮之类的项

1 个答案:

答案 0 :(得分:0)

设置框架而不仅仅是高度

controller.view.frame = CGRect(x: xPosition, y: y, width: width, height: height)

还将autoreszingmaskToconstraint设置为false

controller.view.translatesAutoresizingMaskIntoConstraints = false;