SFSafariViewController does not display correctly when clicked in the UINavigationController with modalPresentationStyle = .FormSheet

I have a simple view of the settings table, which is the first view of the UINavigationController.

I present the UINavigationController settings using the .FormSheet modalPresentationStyle, which means that on the iPhone it takes up the whole screen, while on the iPad it is displayed in the center.

Now I want one of the lines in the settings table to push the SFSafariViewController onto the navigation stack.

This works fine on the iPhone, but on the iPad it is not. IPad Screenshot:

enter image description here

Notice that part of the SFSafariViewController navigation bar appears below the navigation bar (with the back button). See the red rectangle in the image.

let urlText = "http://www.apple.com" let url = NSURL(string: urlText)! let safariViewController = SFSafariViewController(URL: url) self.navigationController?.pushViewController(safariViewController, animated: true) 

On iPhone, you don’t see the SFSafariViewController navigation bar at all - this is perfect for my use.

Any magic setting to make this work right?

+5
source share
3 answers

SFSafariViewController is available for iOS9.0 or higher version of apple os. For your problem, you ran into some kind of problem showing some space in your navigation bar with the SFSafariViewController.because view

enter image description here SFSafariViewController embeds its own navigation bar, UISearchbar, UIBarButton. When you click SFSafariViewController from the ViewController, you show the application navigation bar in the SFSafariViewController navigation bar. enter image here

enter image description here

+3
source

This is not quite a fix, but here is what I did in this situation. Instead of clicking it on the navigation controller, I do the following

 let sfController = SFSafariViewController(URL: NSURL(string:"url")!) sfController.modalPresentationStyle = .FormSheet sfController.modalTransitionStyle = .CrossDissolve presentViewController(sfController, animated: false, completion: nil) 

I had to turn off the animation, because otherwise I tried to insert a view controller on the right. CrossDissolve takes care of the outgoing animation. Perhaps this is not the way you want it, because in your case you want to obscure the URL and keep your navigation bar where this method covers your navigation bar and shows the SFSafariViewController navigation bar. In fact, the SFSafariViewController should not be used that way, although your work around using WKWebView makes more sense in your case.

One more note: using pushViewController will actually reject the entire navigation controller when you click the Finish button in SFSafariViewController, so in most cases presentViewController will be the best way to display if you don't need this type of behavior.

+1
source

I realized that it is not possible to click the SFSafariViewController on a pre-existing UINavigationController . It has its own navigation bar and toolbar.

Despite the fact that on the iPhone (at least on iOS 10+) it works a little well when it is inserted into an existing navigation controller, it has problems with the iPad, so be careful if you do this in a universal application.

In particular, the iPad does not have a toolbar in SFSafariViewController , instead, the open button in Safari is displayed directly in the navigation panel in the upper right corner. Since the SFSafariViewController does not belong to or use the navigation controller that you click on it, the no button in Safari is displayed, and this will be inconvenient for your users.

0
source

Source: https://habr.com/ru/post/1240321/


All Articles