下面的代码执行UiViewController的显示,其中包含一个UiWebView,UiWebView必须显示在全屏上,而它作为下面的图像显示。我尝试了我所知道的所有方法,通过快速编程修改故事板,在下面找到视图代码和源代码--您能解释如何将这个ui and视图放到全屏上吗?我是否也附加了模拟器图像?
ViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
let controller = BrowserViewController()
let navigationController = UINavigationController(rootViewController: controller)
navigationController.modalPresentationStyle = .overFullScreen
self.navigationController?.present(navigationController, animated: true, completion: nil)
}BrowserViewController.swift
import UIKit
func hexStringToRGB(_ hexString: String) -> (red: CGFloat, green: CGFloat, blue: CGFloat) {
var cString: String = hexString.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.count) != 6) {
return (red: 0.0, green: 0.0, blue: 0.0)
}
var rgbValue: UInt32 = 0
Scanner(string: cString).scanHexInt32(&rgbValue)
return (
red: CGFloat((rgbValue & 0xFF0000) >> 16),
green: CGFloat((rgbValue & 0x00FF00) >> 8),
blue: CGFloat(rgbValue & 0x0000FF))
}
class BrowserViewController: UIViewController, UIWebViewDelegate {
//Array che contiene gli url che hanno il permesso di essere visualizzati nella UiWebView
let urlPermessi = ["web.parktogo.it", "m.facebook.com", "www.facebook.com", "paypal.com", "accounts.google.com"]
//Definizione della UIWebView
var myWebView: UIWebView = UIWebView()
let button = UIButton(type: UIButton.ButtonType.custom)
//Definizione url home-page
let urlhomepage = URL (string: "https://web.parktogo.it")
let dictionatyUnclock = NSDictionary(object: "mozilla/5.0 (iphone; cpu iphone os 7_0_2 like mac os x) applewebkit/537.51.1 (khtml, like gecko) version/7.0 mobile/11a501 safari/9537.53", forKey: "UserAgent" as NSCopying)
//Check url
func checkUrl(url: String) {
if(url == "web.parktogo.it" || url == "https://web.parktogo.it") {
self.button.isHidden = true
UserDefaults.standard.register(defaults: dictionatyUnclock as! [String: Any])
}
else {
UserDefaults.standard.register(defaults: dictionatyUnclock as! [String: Any])
self.button.isHidden = false
}
}
//Funzione che permette di tornare alla pagina precedente nella UiWebView
@objc func goBack() {
let request = URLRequest(url: urlhomepage! as URL);
myWebView.loadRequest(request)
checkUrl(url: "https://web.parktogo.it")
}
//Funzione che si occupa della verifica degli url
func ValidazioneURL(url: String) -> Bool {
var check: Bool = true
if urlPermessi.contains(url) {
print("Url valido")
} else {
print("Url non valido")
check = false
}
checkUrl(url: url)
return check;
}
//Funzione eseguita all'avvio della UIWebView
override func viewDidLoad() {
super.viewDidLoad()
self.view.removeAllConstraints()
self.view.backgroundColor = UIColor(white: 1, alpha: 0.5)
self.navigationController?.isNavigationBarHidden = true
UIApplication.shared.keyWindow?.windowLevel = UIWindow.Level.statusBar
//
self.view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
myWebView = UIWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))
//Istanzio la UIWebView
myWebView.delegate = self
//Aggiuge la view all'UIView principale
self.view.addSubview(myWebView)
//Questo codice permette di modificare lo useragent per i response della UiWebView
UserDefaults.standard.register(defaults: dictionatyUnclock as! [String: Any])
//Visualizzo l'url all'interno della uiwebview
let request = URLRequest(url: urlhomepage! as URL);
myWebView.loadRequest(request);
//Istanza del button che permette di tornare alla schermata precendente
let image = UIImage(named: "arrow-back-icon.png")
button.frame = CGRect(x: 0, y: 0, width: 80, height: 150)
button.setImage(image, for: .normal)
button.addTarget(self, action: #selector(goBack), for: .touchUpInside)
//button.backgroundColor = .lightGray
self.view.addSubview(button)
checkUrl(url: "https://web.parktogo.it")
}
//Funzione che viene eseguita ogni volta che verifica gli url presenti nell'array per verificarne la validità
internal func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebView.NavigationType) -> Bool {
var check: Bool = true
do {
//print("Url da verificare = \(request.url!.host!)")
if navigationType == UIWebView.NavigationType.linkClicked {
check = ValidazioneURL(url: request.url!.host!)
}
}
catch is Error {
}
return check
}
//Funzione eseguiata all'inzializzazione della webview
func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebView.NavigationType) -> Bool {
var check: Bool = true
print("Url da verificare = \(request.url!.host!)")
if navigationType == UIWebView.NavigationType.linkClicked {
check = ValidazioneURL(url: request.url!.host!)
}
return check
}
//Funzione eseguiata al caricamento della webview
func webViewDidStartLoad(_ webView: UIWebView) {
print("web view start loading")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
navigationController?.navigationBar.isHidden = true // for navigation bar hide
// UIApplication.sharedApplication.statusBarHidden=true// for status bar hide
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}发布于 2020-04-03 10:27:20
您的UIWebView已经被限制为superView,但是myWebView的UIWebBrowserView显示在safeArea下面。顺便说一句,UIWebView被否决了,请查看下面的链接。

只需将UIWebView更改为WKWebView即可
WebKitimport WebKit这些意大利评论,来自OP的github回购,如此明知故犯地添加在这里
//Definizione della UIWebView
var myWebView = WKWebView()loadRequest行更改为myWebView.load(request)viewDidLoad中myWebView = WKWebView(frame: CGRect(x: 0, y: 0,
width: view.frame.width,
height: view.frame.height))快跑!
奖金
UIWebView被废弃为-> 苹果文档
WKWebView文档-> 苹果文档
WKWebView使用->用斯威夫特
发布于 2020-04-03 09:41:35
您似乎将will视图限制为safeAreaLayout,尝试将其限制为superView,并查看它将如何显示:)
https://stackoverflow.com/questions/61008542
复制相似问题