目前小viewController

时间:2017-03-21 07:33:15

标签: ios swift ipad viewcontroller cgpoint

问题状态:我有两个viewController

  1. parentViewController(375 * 667)
  2. childViewController(300 * 667)
  3. 我想在Axis(75 * 0)上呈现childViewController,如下所示

    enter image description here

    childViewController在此IBAction上显示

    @IBAction func btnShowVC(_ sender: UIButton) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let newVC = storyboard.instantiateViewController(withIdentifier: "cvc") as? childViewController
        self.present(newVC!, animated: true, completion: nil)
    }
    

    但它像

    一样伸展自己

    enter image description here

    anyOne可以帮我解决吗? 感谢

3 个答案:

答案 0 :(得分:2)

image here 你可以这样试试。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let newVC = storyboard.instantiateViewController(withIdentifier: "ChildViewController") as? ChildViewController
            view.addSubview((newVC?.view)!)
        newVC?.view.frame = CGRect(x:75,y:0,width:view.frame.size.width-75,height:view.frame.size.height)
        newVC?.view.autoresizingMask = \[.flexibleWidth, .flexibleHeight\]


        newVC?.didMove(toParentViewController: self)

答案 1 :(得分:1)

您在哪里设置ViewController的框架?如果您使用autolayout,则需要设置约束以使ViewController看起来如您所愿。如果你想以编程方式进行,你可以在某处设置框架,例如在上面发布的代码中你可以这样做:

{{1}}

答案 2 :(得分:0)

通过设置preferredContentSize属性可以解决您的问题,请尝试下面的代码段

newVC?.preferredContentSize = CGSize(width: 300, height: 667)