SFSafariViewController不显示全屏/内容

时间:2016-03-10 22:32:05

标签: ios swift sfsafariviewcontroller

我为一个演示制作了一个非常简单的应用程序,并尝试使用SFSafariViewController来展示网页(我需要使用SFWKWebView,以便能够访问cookie)。

我真的想向User提供一些UI buttons,但我还是无法将其删除。

我尝试了这个代码段(放置在presentViewController()的完成回调中:

let width: CGFloat = 66
let x: CGFloat = self.view.frame.width - width

// It can be any overlay. May be your logo image here inside an imageView.
let overlay = UIView(frame: CGRect(x: x, y: 20, width: width, height: 44))
overlay.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)
svc.view.addSubview(overlay)

... this post中概述。在他们的情况下,他们试图以小视图覆盖重新加载按钮。无论用例如何,对于我来说,当我加载SFSafariViewController时,视图会立即消失(我可以看到它并暂时消失)。

我正在考虑以.OverContext模式显示按钮,但用户将无法与SFSafariViewController进行互动,而border-style也无法正常工作。

这里基本上是我所追求的(原谅粗略,快速的模型)......基本上,SafariViewController上面有一个视图(见底部)......透明度只是为了表明它通过Safari呈现。)

enter image description here

非常感谢任何建议。

1 个答案:

答案 0 :(得分:1)

想出来......可能会出现一些轻微的竞争条件,这会妨碍推荐的“绘制矩形”代码按照需要运行。我做了什么:

  • Subclassed SFSafariWebViewController
  • viewDidAppear中,使用绘制任何其他视图元素的NSTimer实施了轻微延迟

这也最终帮我隐藏了状态栏,这给了我一些问题(见模型)。

以下是相关代码:

import UIKit
import SafariServices

class MySafariVC: SFSafariViewController {

    override func viewDidLoad() {
         super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        var frame = self.view.frame
        let OffsetY: CGFloat  = 44
        frame.origin = CGPoint(x: frame.origin.x, y: frame.origin.y - OffsetY)
        frame.size = CGSize(width: frame.width, height: frame.height + (1 * OffsetY))
        self.view.frame = frame

        NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "drawNavBar", userInfo: nil, repeats: false)
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        print("i laid out my subviews")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prefersStatusBarHidden() -> Bool {
        return true
    }

    func drawNavBar() {
        let height: CGFloat = 44
        let y: CGFloat = self.view.frame.height - height

        // It can be any overlay. May be your logo image here inside an imageView.
        let overlay = UIView(frame: CGRect(x: 0, y: y, width: self.view.frame.width, height: height))
        overlay.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.9)
        self.view.addSubview(overlay)
    }
}