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