SFSafariViewController:有时不会出现叠加

时间:2016-11-10 11:32:37

标签: ios swift sfsafariviewcontroller

我正在使用SFSafariViewController,因为我不想显示safari的状态栏,我通过添加叠加隐藏了它。我在覆盖层上有自己的按钮,工作正常。 Safari状态栏是隐藏的,它显示我的叠加层,但有时候叠加层会消失,并且可以看到safari状态栏。我怀疑它是因为链接是自动重新加载但是如何?我只打电话一次。我不知道为什么叠加有时会消失。下面是我的代码 -

self.navigationController?.presentViewController(sfController!, animated: true, completion: { 
            let bounds = UIScreen.mainScreen().bounds
            let overlay = UIView(frame: CGRect(x: 0, y: 0, width: bounds.size.width, height: 65))
            overlay.backgroundColor = UIColor(netHex: 0x275E37)
            let completedBtn = UIButton()
            let favBtn = UIButton()

            let image = UIImage(named: "home.png") as UIImage?
            let homeBtn   = UIButton(type: UIButtonType.Custom) as UIButton
            homeBtn.frame = CGRectMake(20, 25, 35, 35)
            homeBtn.setImage(image, forState: .Normal)
            homeBtn.addTarget(self, action: #selector(DetailsViewController.HomeBtnAction), forControlEvents:.TouchUpInside)

            completedBtn.setTitle("Mark as Completed",forState: .Normal)
            completedBtn.titleLabel!.font =  UIFont(name: "FidelitySans-Regular", size: 20)
            completedBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal)
            completedBtn.frame = CGRectMake((bounds.size.width - 210), 25, 200, 35)
            completedBtn.backgroundColor = UIColor(netHex: 0x6F9824)
            completedBtn.addTarget(self, action: #selector(DetailsViewController.CompletedAction), forControlEvents: UIControlEvents.TouchUpInside)

            favBtn.setTitle("Save as Favorite", forState: .Normal)
            favBtn.titleLabel!.font =  UIFont(name: "FidelitySans-Regular", size: 20)
            favBtn.setTitleColor(UIColor.whiteColor(), forState: .Normal)
            favBtn.frame = CGRectMake((bounds.size.width - 420), 25, 200, 35)
            favBtn.backgroundColor = UIColor(netHex: 0x6F9824)
            favBtn.addTarget(self, action: #selector(DetailsViewController.FavoriteAction), forControlEvents: UIControlEvents.TouchUpInside)

            overlay.addSubview(favBtn)
            overlay.addSubview(completedBtn)
            overlay.addSubview(homeBtn)
            self.sfController!.view.addSubview(overlay)


        })

任何帮助将不胜感激,因为我长时间陷入这个问题并且无法解决问题。谢谢!

2 个答案:

答案 0 :(得分:0)

不允许您尝试做什么。应始终按原样显示SFSafariViewController。

相反,您可以使用WKWebView构建应用内浏览器并添加自定义控件。

答案 1 :(得分:0)

我通过在safariViewController委托方法didCompleteInitialLoad中添加overlay来获得解决方案。因此,直到didCompleteInitialLoad方法被调用之前具有透明深色背景的指示符,一旦URL被完全加载,将调用didCompleteInitialLoad并且不将覆盖添加到此方法中的safariviewcontroller。像下面的代码一样,它总是在堆栈顶部。

self.sfController?.view.insertSubview(overlay, atIndex: (self.sfController?.view.subviews.count)!)