问题状态:我有两个viewController
我想在Axis(75 * 0)上呈现childViewController,如下所示
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)
}
但它像
一样伸展自己anyOne可以帮我解决吗? 感谢
答案 0 :(得分:2)
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)