Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 按下QLViewController并将半透明设置为false?_Ios_Swift - Fatal编程技术网

Ios 按下QLViewController并将半透明设置为false?

Ios 按下QLViewController并将半透明设置为false?,ios,swift,Ios,Swift,我无法禁用QLPreviewController的半透明属性。我已经尝试过的: let preview = SideQLPreviewController() preview.navigationController?.navigationBar.isTranslucent = false //before self.navigationController?.pushViewController(preview, animated: false) preview.navigationC

我无法禁用QLPreviewController的半透明属性。我已经尝试过的:

 let preview = SideQLPreviewController()
 preview.navigationController?.navigationBar.isTranslucent = false //before
 self.navigationController?.pushViewController(preview, animated: false)
 preview.navigationController?.navigationBar.isTranslucent = false //after
 self.navigationController?.navigationBar.isTranslucent = false 
并且已经尝试子类化并设置:

class SideQLPreviewController: QLPreviewController {

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController?.navigationBar.isTranslucent = false
    // Do any additional setup after loading the view.
}

但是仍然没有成功-有什么想法吗?

如果您展示的是
QLPreviewController
则根本没有导航控制器。不过,类似的方法可能会奏效:

class PreviewController: QLPreviewController {
    var navigationBar: UINavigationBar? {
        return view.recursiveSubviews.filter({ $0 is UINavigationBar }).first as? UINavigationBar
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationBar?.isTranslucent = false
    }
}

extension UIView {
    var recursiveSubviews: [UIView] {
        var recursiveSubviews: [UIView] = []
        for subview in subviews {
            recursiveSubviews.append(subview)
            recursiveSubviews.append(contentsOf: subview.recursiveSubviews)
        }
        return recursiveSubviews
    }
}

你可以在你的子类的viewDidLayoutSubviews中完成,这对我很有用

class PreviewController: QLPreviewController {

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        navigationController?.navigationBar.isTranslucent = false
    }
}
然后实例化新类

let previewController = PreviewController()//QLPreviewController()
previewController.dataSource = self
navigationController?.pushViewController(previewController, animated: true)