如果您对如何在Swift中的UIWebView中加载URL?感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何在Swift中的UIWebView中加载URL?的详细内容,我
如果您对如何在Swift中的UIWebView中加载URL?感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于如何在Swift中的UIWebView中加载URL?的详细内容,我们还将为您解答swift uiview的相关问题,并且为您提供关于css – 我们如何在ios 9中的uiwebview中禁用放大镜 – Swift、iOS Swift:无法检索UIwebView中加载的当前url、ios – SWIFT:为什么我无法在UIWebView中加载当前的URL?、ios – UIScrollView中的UIWebView的有价值信息。
本文目录一览:- 如何在Swift中的UIWebView中加载URL?(swift uiview)
- css – 我们如何在ios 9中的uiwebview中禁用放大镜 – Swift
- iOS Swift:无法检索UIwebView中加载的当前url
- ios – SWIFT:为什么我无法在UIWebView中加载当前的URL?
- ios – UIScrollView中的UIWebView
如何在Swift中的UIWebView中加载URL?(swift uiview)
我有以下代码:
UIWebView.loadRequest(NSURLRequest(URL: NSURL(string: "google.ca")))
我收到以下错误:
“ NSURLRequest”不可转换为UIWebView。
知道是什么问题吗?
答案1
小编典典loadRequest:是实例方法,不是类方法。您应该尝试使用UIWebview的实例作为接收者而不是类本身来调用此方法。
webviewInstance.loadRequest(NSURLRequest(URL: NSURL(string: "google.ca")!))
但是,正如@radex在下面正确指出的那样,您还可以利用currying来调用如下函数:
UIWebView.loadRequest(webviewInstance)(NSURLRequest(URL: NSURL(string: "google.ca")!))
斯威夫特5
webviewInstance.load(NSURLRequest(url: NSURL(string: "google.ca")! as URL) as URLRequest)
css – 我们如何在ios 9中的uiwebview中禁用放大镜 – Swift
我使用下面的代码禁用uiwebview中的选择/复制..:
* { -webkit-touch-callout: none; -webkit-user-select: none; /* disable selection/copy in UIWebView */ }
它的工作原理,但问题是ios 9中的新放大镜,所以有没有解决方案来禁用它?
注意:我不使用Cordova
解决方法
这将覆盖webView中的长按.
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:nil action:NULL]; longPress.minimumPressDuration = 0.2; [webView addGestureRecognizer:longPress];
迅速
let longPress:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: nil,action: nil) longPress.minimumPressDuration = 0.2 webView.addGestureRecognizer(longPress)
iOS Swift:无法检索UIwebView中加载的当前url
我面临的问题是我想得到webview显示的每个网址:
在网址上我必须执行一些if else检查.但我无法得到webview加载的网址.
webview显示精细结果并在点击时加载网址.我想获取webview导航的所有网址.
import Foundation import UIKit class seconVC: UIViewController { var toPass:String! var touser:String! var toPassing:String! @IBOutlet weak var webV: UIWebView! @IBOutlet weak var L_back: UIBarButtonItem! @IBOutlet weak var R_frwrd: UIBarButtonItem! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. var domurl = toPass; var username = touser; var passwing = toPassing; var sendurl = stringA+username+"/"+passwing; //exchange login with auth/username/password println(sendurl); let url = NSURL (string: sendurl); let requestObj = NSURLRequest(URL: url!); webV.userInteractionEnabled = true webV.loadRequest(requestObj); } @IBAction func L_back(sender: UIBarButtonItem) { if (webV.canGoBack){ webV.goBack() } } @IBAction func R_frwrd(sender: UIBarButtonItem) { if (webV.canGoForward){ webV.goForward() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // dispose of any resources that can be recreated. } }
我想要的是为webview获取当前网址和导航按钮的字符串:请帮助?我提到所有互联网没有解决方案在我的情况下工作.
解决方法
斯威夫特3
if let currentURL = webView.request?.url?.absoluteString{ print(currentURL) }
正如它提到的here.
ios – SWIFT:为什么我无法在UIWebView中加载当前的URL?
这是代码
var currentURL : Nsstring = webView.request?.URL.absoluteString!
这有什么问题?
解决方法
let currentURL : Nsstring = (webView.request?.URL.absoluteString)!
ios – UIScrollView中的UIWebView
*由于未捕获的异常’CALayerInvalidGeometry’而终止应用程序,原因:’CALayer位置包含NaN:[nan nan]’
使用以下堆栈跟踪:
Thread 1,Queue : (null) #0 0x01dd5caa in objc_exception_throw () #1 0x01f5da48 in +[NSException raise:format:arguments:] () #2 0x01f5d9b9 in +[NSException raise:format:] () #3 0x007e8c0d in CA::Layer::set_position(CA::Vec2<double> const&,bool) () #4 0x007def55 in -[CALayer setPosition:] () #5 0x037b07d3 in -[WebFixedPositionContent scrollOrZoomChanged:] () #6 0x00a5bfae in -[UIWebDocumentView _updateFixedPositionContent] () #7 0x00c66ff3 in -[UIWebbrowserView _updateFixedPositionContent] () #8 0x00a5b07e in -[UIWebDocumentView _didScroll] () #9 0x01fb6dea in -[NSObject performSelector:] () #10 0x01f207f1 in -[NSArray makeObjectsPerformSelector:] () #11 0x0091627d in -[UIScrollView(Static) _notifyDidScroll] () #12 0x009029ae in -[UIScrollView setContentOffset:] () #13 0x00909ac8 in -[UIScrollView _updatePanGesture] () #14 0x0090d3c0 in -[UIScrollView handlePan:] () #15 0x00b84e29 in _UIGestureRecognizerSendActions () #16 0x00b84133 in -[UIGestureRecognizer _updateGestureWithEvent:] () #17 0x00b853bf in -[UIGestureRecognizer _delayedUpdateGesture] () #18 0x00b87a21 in ___UIGestureRecognizerUpdate_block_invoke_0541 () #19 0x00b8797c in _UIGestureRecognizerApplyBlocksToArray () #20 0x00b803d7 in _UIGestureRecognizerUpdate () #21 0x008e51a2 in -[UIWindow _sendGesturesForEvent:] () #22 0x008e5532 in -[UIWindow sendEvent:] ()
我已经看过很多有关这方面的问题和答案,并意识到苹果不鼓励这样做,但我没有看到任何提供替代方案的答案.
我的第一个问题:是否有另一种方法可以达到同样的效果?
下面是我如何创建UIWebView的片段
- (void) createWebView:(Nsstring*)url{ NSInteger requestedHeight = 480; NSInteger requestedWidth = 640; self.webContent = [[UIWebView alloc] initWithFrame: CGRectMake(0,self.frame.size.height,requestedWidth,requestedHeight)]; self.webContent.scrollView.userInteractionEnabled = NO; self.webContent.scrollView.scrollEnabled = NO; self.webContent.scrollView.bounces = NO; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; [self.webContent loadRequest:urlRequest]; [self addSubview:self.webContent]; NSInteger calculatedHeight = self.webContent.frame.origin.y + self.webContent.frame.size.height; NSInteger calculatedWidth = self.webContent.frame.origin.x + self.webContent.frame.size.width; if (calculatedHeight > self.frame.size.height || calculatedWidth > self.frame.size.width){ self.frame = CGRectMake(self.frame.origin.x,self.frame.origin.y,MAX(self.frame.size.width,calculatedWidth),MAX(self.frame.size.height,calculatedHeight + 5)); } }
如您所见,我禁用了UIWebView的滚动和用户输入.
我的第二个问题:当我明确禁用该功能时,为什么UIWebView(或至少一个或多个子视图)处理滚动?
我的第三个问题:因为它似乎正在处理滚动,是否有任何其他方法来拦截或禁用发送到UIWebView的滚动通知?
如您所见,我并不打算让用户与UIWebView的内容进行交互 – 只是让他们看到内容.
在这种情况下,可能的替代方案是以某种方式在UIScrollView之外创建一个用户不可见的UIWebView,将其内容捕获到图像中,然后在UIImageView中显示内容?如果是这样,我如何将UIWebView的内容捕获到图像中?
编辑:
我找到了一个非常简单的解决方案.基本上加载UIWebView但不要将其添加为子视图.当UIWebView完成加载时,使用以下代码创建图像:
- (void)webViewDidFinishLoad:(UIWebView *)webView{ UIGraphicsBeginImageContext(self.webContent.bounds.size); [self.webContent.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetimageFromCurrentimageContext(); UIGraphicsEndImageContext(); [self.imageContent setimage:image]; }
我仍然有兴趣听取问题1到3的答案.将来,如果我们决定支持交互式UIWebView,这个解决方案将无效.
有什么建议?
解决方法
今天关于如何在Swift中的UIWebView中加载URL?和swift uiview的分享就到这里,希望大家有所收获,若想了解更多关于css – 我们如何在ios 9中的uiwebview中禁用放大镜 – Swift、iOS Swift:无法检索UIwebView中加载的当前url、ios – SWIFT:为什么我无法在UIWebView中加载当前的URL?、ios – UIScrollView中的UIWebView等相关知识,可以在本站进行查询。
本文标签: