XIB 文件在 iOS Swift 中适合整个屏幕

XIB file is fitted with whole screen in iOS Swift

我一直在尝试在使用当前模式时在整个屏幕上显示 UIViewController

这是输出图像

[![在此处输入图片描述][1]][1]

我有 xib viewController,我正在尝试使用当前方法向另一个 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)

通常你可以show/present你的视图有两种方式。

创建 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)
}

UIViewControllerXIB 文件一起使用的情况下,它只会更改 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)
              }