| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- //
- // DetailCellWeb.m
- // Apex Mobile
- //
- // Created by Ray on 14-3-7.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "DetailCellWeb.h"
- @implementation DetailCellWeb
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- // Initialization code
- }
- return self;
- }
- - (id)init
- {
- self = [super init];
- if(self)
- {
-
- WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
-
- WKPreferences *preferences = [WKPreferences new];
- preferences.javaScriptCanOpenWindowsAutomatically = YES;
- // preferences.minimumFontSize = 40.0;
-
- configuration.preferences = preferences;
-
- self.webView = [[WKWebView alloc] initWithFrame:self.bounds configuration:configuration];
- // self.webView.UIDelegate = self;
- // self.wkwebView.navigationDelegate = self;
- self.webView.scrollView.bounces = false;
- [self addSubview:self.webView];
-
- // __weak typeof(self) weakSelf = self;
- // [self.webView.scrollView setEmptyContentViewBackgroupColor:UIColor.whiteColor];
- // self.webView.scrollView.emptyView = [RAEmptyView emptyViewWithTitle:@"can not reach the server.\ntap to reload" clickHandler:^(id sender) {
- // [weakSelf LoadFromURL:weakSelf.url];
- // }];
-
-
-
-
- }
- return self;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated
- {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)willMoveToSuperview:(UIView *)newSuperview {
-
-
-
- // NSString* source = @"var meta = document.createElement('meta');meta.name = 'viewport';meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';var head = document.getElementsByTagName('head')[0];head.appendChild(meta);";
- // WKUserScript * script= [[WKUserScript alloc] initWithSource:source injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:true];
- //// WKUserContentController* cc = [[WKUserContentController alloc] init];
- // [self.webView.configuration.userContentController addUserScript:script];
-
- // let userContentController: WKUserContentController = WKUserContentController()
- // let conf = WKWebViewConfiguration()
- // conf.userContentController = userContentController
- // userContentController.addUserScript(script)
-
-
- if (newSuperview) {
-
- NSString* source = @"var meta = document.createElement('meta');meta.name = 'viewport';meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0 user-scalable=no';var head = document.getElementsByTagName('head')[0];head.appendChild(meta);";
- WKUserScript * script= [[WKUserScript alloc] initWithSource:source injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:true];
- [self.webView.configuration.userContentController addUserScript:script];
-
-
- NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld;
- [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:options context:nil];
- } else {
- [self.webView.scrollView removeObserver:self forKeyPath:@"contentSize"];
- }
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
-
- if ([keyPath isEqualToString:@"contentSize"]) {
-
- // NSLog(@"contentSize");
-
- // CGSize old = [change[@"old"] CGSizeValue];
- CGSize new = [change[@"new"] CGSizeValue];
-
- if (new.height != 0) {
- self.webView.scrollView.contentSize = CGSizeMake(new.width, 0);
- }
-
- }
- }
- - (void)prepareForReuse {
- [self.webView stopLoading];
- [super prepareForReuse];
- }
- @end
|