iphone打开文本视图中的超连接显示在网页视图中。opening links in a UITextView in a web view
2011-04-01 15:33
465 查看
当设定了文本内容的链接高亮事件监听后,UIApplication将对点击事件做出responser,比如调用safari处理http文本,如果要改变这种响应方法。怎么做?
Method1、
使用类别override UITextView的webView:decidePolicyForNavigationAction:request:frame:decisionListener:方法。
UITextView增加了类别,重写了方法。但必须注意这是一个private API。如果内部框架调整可能导致实效。
Method2、
重写UIApplication openURL方法
还有个实现不通过重写方法,而是先命名别称然后交换方法实现。swap implementations between separate methods.
所以总结下来还是推荐使用第二种方法。
详见地址:https://github.com/marksands/UITextViewLinkOptions
Method1、
使用类别override UITextView的webView:decidePolicyForNavigationAction:request:frame:decisionListener:方法。
@interface UITextView (CommonOverrid) @end @class WebView, WebFrame; @protocol WebPolicyDecisionListener; @implementation UITextView (CommonOverrid) - (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id < WebPolicyDecisionListener >)listener { NSLog(@"request: %@", request); UIWebView *v1 = [[UIWebView alloc] initWithFrame:CGRectMake(0, self.superview.frame.size.height - 200, 764, 200)]; [v1 loadRequest:request]; [((UIView *)(self.superview)) addSubview:v1]; }
UITextView增加了类别,重写了方法。但必须注意这是一个private API。如果内部框架调整可能导致实效。
Method2、
重写UIApplication openURL方法
@implementation UIApplication (Private) - (BOOL)openURL:(NSURL*)url { //current delegate MyAppDelegate *watcher = [[UIApplication sharedApplication] delegate]; //current controller,use it to handleURL the action if (watcher.currentViewController) { //do something here.... [watcher.currentViewController handleURL:url]; return YES; } return NO; } @end
还有个实现不通过重写方法,而是先命名别称然后交换方法实现。swap implementations between separate methods.
Method customOpenUrl = class_getInstanceMethod([UIApplication class], @selector(customOpenURL:)); Method openUrl = class_getInstanceMethod([UIApplication class], @selector(openURL:)); method_exchangeImplementations(customOpenUrl, openUrl);
所以总结下来还是推荐使用第二种方法。
详见地址:https://github.com/marksands/UITextViewLinkOptions
相关文章推荐
- iphone打开文本视图中的超连接显示在网页视图中。opening links in a UITextView in a web view
- iPhone开发 No IB 添加一个webview来显示网页
- Android开发中使用WebView视图显示网页的注意点
- Android-使用WebView视图显示网页
- webview内网页的连接内置打开,不用手机的浏览器打开;设置网页进度条progress
- Android中的WebView打开网页,以及对当前网页的缩放等,网络连接判断
- 浅谈WebView视图显示网页
- Android Webview调相机拍照选择图片并显示到网页
- WebView加载网页图片显示不全或显示不完整
- 用WebView显示assets里的HTML文本
- android webview 加载网页显示不完整解决办法
- WebView加载网页不显示图片解决办法
- Android:控件WebView显示网页
- Android:控件WebView显示网页
- 3.4 WebView显示网页
- webView 显示一个简单的网页
- 网页浏览控件WebView和显示进度的对话框ProgressDialog
- Android:控件WebView显示网页
- Android——使用WebView显示网页
- WebView打开网页,设置支持Javascript,浏览的网页后退而不是退出浏览器,判断页面加载过程,缓存的使用