2016-11-10 83 views
0

我正在使用SFSafariViewController,并且因为我不想显示safari的状态栏,所以我通过添加叠加层来隐藏它。我在覆盖层上有自己的按钮,并且工作正常。 Safari浏览器状态栏是隐藏的,它显示我的覆盖图,但不知何故,有时覆盖层消失,Safari浏览器状态栏可见。我怀疑它是因为链接自动重新加载,但是如何?我只调用一次。我不知道为什么叠加层有时候会消失。下面是我的代码 -SFSafariViewController:Overlay有时不会出现

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) 


     }) 

任何帮助将不胜感激,因为我长时间停留在这个问题和不能很好的解决方案。谢谢!

回答

0

你试图做的事情是不允许的。应始终按照原样呈现SFSafariViewController。

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

+0

我有一个情景,由于我不能使用webview。我必须使用safari。 –

0

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

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