Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
93 lines (81 loc) · 3.15 KB

File metadata and controls

93 lines (81 loc) · 3.15 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// EALocalCodeViewController.m
// Coding_iOS
//
// Created by Easeeeeeeeee on 2018/3/28.
// Copyright © 2018年 Coding. All rights reserved.
//
#import "EALocalCodeViewController.h"
#import "WebContentManager.h"
@interface EALocalCodeViewController ()<UIWebViewDelegate>
@property (strong, nonatomic) UIWebView *webContentView;
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
@end
@implementation EALocalCodeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = _curURL.lastPathComponent;
{//用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);
}];
}
[self loadData];
}
- (void)loadData{
if ([_curURL isTextData]) {
CodeFile *file = [CodeFile codeFileWithLocalURL:_curURL];
NSString *codeStr = [WebContentManager codePatternedWithContent:file isEdit:NO];
[self.webContentView loadHTMLString:codeStr baseURL:nil];
}else{
[self.webContentView loadRequest:[NSURLRequest requestWithURL:_curURL]];
}
}
#pragma mark - Orientations
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
#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];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
[_activityIndicator stopAnimating];
if (error.code == NSURLErrorCancelled) {
NSLog(@"Canceled request: %@", webView.request.URL);
}else if ([error.domain isEqualToString:@"WebKitErrorDomain"] && (error.code == 102 || error.code == 204)) {
NSLog(@"ignore: %@", error);
}else {
[NSObject showError:error];
}
}
@end
Morty Proxy This is a proxified and sanitized view of the page, visit original site.