gpt4 book ai didi

ios - MyScript 如何将 mathwidget 添加为另一个 UIViewController 中的 subview

转载 作者:行者123 更新时间:2023-11-30 12:25:11 25 4
gpt4 key购买 nike

如何将 mathwidget 添加为另一个 UIViewController 中的 subview 目前,mathwidget 在加载 UIViewController 时工作正常。 让 subViewEE = MathWidgetClassName() self.present(subViewEE, 动画: true, 完成: nil)

但是当我尝试将其添加为当前 View Controller 内的 subview 时,没有显示任何内容,代码如下:

let mathWidget= MathWidgetClassName()
self.addChildViewController(mathWidget)
self.view.addSubview(mathWidget.view)
mathWidget.didMove(toParentViewController: self)

任何人都可以帮助将 MathWidget 显示为当前 UIViewController 中的 subview 吗?

最佳答案

您正在以编程方式创建 View Controller ,然后您需要设置它的框架和背景颜色,

    let mathWidget = MathWidgetClassName()
mathWidget.view.bounds = self.view.bounds
mathWidget.view.backgroundColor = UIColor.green // you should set white here , it is for demonstration
self.addChildViewController(mathWidget)
self.view.addSubview(mathWidget.view)
mathWidget.didMove(toParentViewController: self)

如果 Storyboard中有 View Controller ,那么您应该这样做,

   let mathWidget = self.storyboard?.instantiateViewController(withIdentifier: "storyBoardID")  //storyBoardID is Storyboard id - can be set from identity inspector of storyboard
// mathWidget?.view.bounds = self.view.bounds
// mathWidget?.view.backgroundColor = UIColor.green
self.addChildViewController(mathWidget!)
self.view.addSubview((mathWidget?.view)!)
mathWidget?.didMove(toParentViewController: self)

关于ios - MyScript 如何将 mathwidget 添加为另一个 UIViewController 中的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44299921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com