我无法禁用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
    }
}

关于ios - 推送QLPreviewController并将Translucent设置为false?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42886797/

10-10 17:49