ios - XIB 文件在 iOS Swift 中适合全屏
问题描述
我一直在尝试UIViewController
在使用当前模式时在整个屏幕上显示?
这是输出图像
[![在此处输入图像描述][1]][1]
我有 xib viewController,我试图使用 present 方法将值发送到另一个 viewController,但它不适合全屏显示。
这是代码:
let vc = TabBarViewController()
vc.processDefID = keyVal
vc.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
vc.modalPresentationStyle = .overFullScreen //or .overFullScreen for transparency
self.present(vc, animated: true, completion: nil)
另一种方法尝试:
var clientView: UIViewcontroller
let V = TabBarViewController()
self.clientView?.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.clientView?.addChild(V)
self.clientView?.view.addSubview(V.view)
V.processDefID = keyVal
V.view.frame = (self.clientView?.view.bounds)!
V.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
V.modalPresentationStyle = .fullScreen
self.present(V, animated: true, completion: nil)
解决方案
通常,您可以通过两种方式显示/呈现您的视图。
创建UIViewController
对象并以您正在做的方式呈现它
func presentView() {
let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ScannerViewController")
vc.view.backgroundColor = .red
vc.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
}
在UIViewController
与XIB
文件一起使用的情况下,它只会更改 ViewController 初始化部分而不是其他任何东西,就像
let vc = ScannerViewController(nibName: "ScannerView", bundle: nil)
创建UIViewController
对象并按以下方式插入它,您还可以将自定义框架分配给它的UIView
对象。
func presentView() {
let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ScannerViewController")
vc.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height/2)
vc.view.backgroundColor = .red
self.addChild(vc)
self.view.addSubview(vc.view)
}
推荐阅读
- javascript - 修改 svg 路径以删除填充部分
- amazon-web-services - 使用 AWS API Gateway 映射 URL 查询字符串参数
- c++ - strcpy克隆函数的C++代码问题
- c# - NuGet - 在构建时获取最新的 lib 版本
- python - 使用 dataframe.column 重命名列后,熊猫合并给出 Nan 值
- javascript - 在小数范围内调整位置
- azure - Azure 区域中托管的 HANA 数据库和 SAP 具有高延迟
- javascript - 在另一个 div 中滚动时更改 div 背景颜色
- tomcat - Apache tomcat 从版本 7 升级到 9
- oracle - ORA-01873: 返回 INTERVAL DAY TO SECOND 的领先精度