Reputation: 492
I am using SFSafariViewController, and as i did not wanted to show the status bar of safari and i have hidden it by adding a overlay. I have my own button on the overlay and its working fine. The safari status bar is hidden and it shows my overlay but somehow sometimes the overlay disappears and the safari status bar is visible. I doubt that its because the link is being reloaded automatically but how? I am only calling it once. I am not sure why overlay is disappear for sometimes only. below is my code -
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)
})
Any help will be much appreciated as i am stuck in this issue from long time and cant fine solution. Thanks!
Upvotes: 1
Views: 655
Reputation: 492
I got solution by adding overlay in the safariViewController delegate method didCompleteInitialLoad. So a indicator with transparent dark background until the didCompleteInitialLoad method is not called, once the URL is fully loaded didCompleteInitialLoad will be called and not add the overlay to safariviewcontroller in this method. like below code so that its always on the top of the stack.
self.sfController?.view.insertSubview(overlay, atIndex: (self.sfController?.view.subviews.count)!)
Upvotes: 1
Reputation: 6102
What you are trying to do is not allowed. SFSafariViewController should always be presented as it is.
Instead, you could use WKWebView to build an in-app browser and add custom controls.
Upvotes: 0