IOS开源项目Coding学习笔记(4):SVWebViewController: 服务条款界面



1、进入代码

 
 
  1. NSString *pathForServiceterms = [[NSBundle mainBundle] pathForResource:@"service_terms" ofType:@"html"];
  2.    WebViewController *vc = [WebViewController webVCWithUrlStr:pathForServiceterms];
  3.    [self.navigationController pushViewController:vc animated:YES];

app的目录下有个service_terms.html的html文件


2、SVWebViewController

 
 
  1. @interface WebViewController : SVWebViewController

继承自SVWebViewController,这个是github上面的一个开源库,https://github.com/TransitApp/SVWebViewController,

只不过这里为了处理统一方便,对这个开源库进行的改造,让他继承了BaseViewController,

而且封装了一个类方法

 
 
  1. + (instancetype)webVCWithUrlStr:(NSString *)curUrlStr;

3、网页加载进度指示

 
 
  1. @property (strong, nonatomic) NJKWebViewProgress *progressProxy;
  2. @property (strong, nonatomic) NJKWebViewProgressView *progressView;

这个也是网上的一个第三方库

https://github.com/ninjinkun/NJKWebViewProgress


4、这个类中有几点需要注意的东西:

4.1、

  
  
  1. @interface SVWebViewController () <UIWebViewDelegate>

SVWebViewController 类本身实现了协议UIWebViewDelegate,然而:

  
  
  1. @interface WebViewController ()<UIWebViewDelegate>

WebViewController又去实现协议UIWebViewDelegate,而且

  
  
  1. @interface WebViewController : SVWebViewController
WebViewController又继承自SVWebViewController,所以其实WebViewController

没有必要实现UIWebViewDelegate协议,因为本身就是多态重写。

还有一点, 这里SVWebViewController中的实现UIWebViewDelegate的方法是执行不到的


4.2、

因为NJKWebViewProgress也实现了WebViewController代理中的方法,用来设置进度,

  
  
  1. _progressProxy = [[NJKWebViewProgress alloc] init];
  2.    self.delegate = _progressProxy; //这里通过delegate调用NJKWebViewProgress 中实现的方法

主要需要注意的点就是这几个UIWebViewDelegate的协议实现别弄混就行了。

5、右上角的分享按钮,这个就后面在分析了

  
  
  1. - (void)shareItemClicked{
  2.    NSURL *url = self.webView.request.URL;
  3.    if (url.absoluteString && ![url.absoluteString isEmpty]) {
  4.        [CodingShareView showShareViewWithObj:self.webView];
  5.    }
  6. }

6、一些介绍webView的网站

http://www.superqq.com/blog/2015/07/08/uiwebviewyong-fa-xiang-jie/

http://blog.csdn.net/totogo2010/article/details/7686164


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值