|
| 1 | +// |
| 2 | +// HtmlMediaViewController.m |
| 3 | +// Coding_iOS |
| 4 | +// |
| 5 | +// Created by Ease on 2016年11月4日. |
| 6 | +// Copyright © 2016年 Coding. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "HtmlMediaViewController.h" |
| 10 | +#import "WebContentManager.h" |
| 11 | + |
| 12 | +@interface HtmlMediaViewController ()<UIWebViewDelegate> |
| 13 | +@property (strong, nonatomic) UIWebView *webContentView; |
| 14 | +@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator; |
| 15 | + |
| 16 | +@property (strong, nonatomic) HtmlMedia *htmlMedia; |
| 17 | +@end |
| 18 | + |
| 19 | +@implementation HtmlMediaViewController |
| 20 | ++ (instancetype)instanceWithHtmlMedia:(HtmlMedia *)htmlMedia title:(NSString *)title{ |
| 21 | + HtmlMediaViewController *vc = [self new]; |
| 22 | + vc.htmlMedia = htmlMedia; |
| 23 | + vc.title = title ?: @"评论详情"; |
| 24 | + return vc; |
| 25 | +} |
| 26 | + |
| 27 | +- (void)viewDidLoad { |
| 28 | + [super viewDidLoad]; |
| 29 | + // Do any additional setup after loading the view. |
| 30 | + self.view.backgroundColor = kColorTableBG; |
| 31 | + {//用webView显示内容 |
| 32 | + _webContentView = [[UIWebView alloc] initWithFrame:self.view.bounds]; |
| 33 | + _webContentView.delegate = self; |
| 34 | + _webContentView.backgroundColor = [UIColor clearColor]; |
| 35 | + _webContentView.opaque = NO; |
| 36 | + _webContentView.scalesPageToFit = YES; |
| 37 | + [self.view addSubview:_webContentView]; |
| 38 | + //webview加载指示 |
| 39 | + _activityIndicator = [[UIActivityIndicatorView alloc] |
| 40 | + initWithActivityIndicatorStyle: |
| 41 | + UIActivityIndicatorViewStyleGray]; |
| 42 | + _activityIndicator.hidesWhenStopped = YES; |
| 43 | + [_activityIndicator setCenter:CGPointMake(CGRectGetWidth(_webContentView.frame)/2, CGRectGetHeight(_webContentView.frame)/2)]; |
| 44 | + [_webContentView addSubview:_activityIndicator]; |
| 45 | + [_webContentView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 46 | + make.edges.equalTo(self.view); |
| 47 | + }]; |
| 48 | + } |
| 49 | + NSString *contentStr = [WebContentManager markdownPatternedWithContent:_htmlMedia.contentOrigional]; |
| 50 | + [self.webContentView loadHTMLString:contentStr baseURL:nil]; |
| 51 | +} |
| 52 | + |
| 53 | +#pragma mark UIWebViewDelegate |
| 54 | +- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ |
| 55 | + DebugLog(@"strLink=[%@]",request.URL.absoluteString); |
| 56 | + UIViewController *vc = [BaseViewController analyseVCFromLinkStr:request.URL.absoluteString]; |
| 57 | + if (vc) { |
| 58 | + [self.navigationController pushViewController:vc animated:YES]; |
| 59 | + return NO; |
| 60 | + } |
| 61 | + return YES; |
| 62 | +} |
| 63 | +- (void)webViewDidStartLoad:(UIWebView *)webView{ |
| 64 | + [_activityIndicator startAnimating]; |
| 65 | +} |
| 66 | +- (void)webViewDidFinishLoad:(UIWebView *)webView{ |
| 67 | + [_activityIndicator stopAnimating]; |
| 68 | +} |
| 69 | + |
| 70 | +@end |
0 commit comments