mirror of
https://github.com/leanote/leanote-ios.git
synced 2025-10-15 15:40:44 +00:00
WKWebView init by code
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
<key>AutocorrectionType</key>
|
||||
<string>No</string>
|
||||
<key>DefaultValue</key>
|
||||
<string>2.3 (3095)</string>
|
||||
<string>2.3 (30A4)</string>
|
||||
<key>IsSecure</key>
|
||||
<false/>
|
||||
<key>Key</key>
|
||||
|
@@ -17,7 +17,6 @@
|
||||
<outlet property="refreshButton" destination="6" id="49"/>
|
||||
<outlet property="toolbar" destination="3" id="8"/>
|
||||
<outlet property="view" destination="1" id="14"/>
|
||||
<outlet property="webView" destination="5" id="9"/>
|
||||
</connections>
|
||||
</placeholder>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
@@ -25,15 +24,6 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<wkWebView contentMode="scaleToFill" id="5">
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="436"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<wkWebViewConfiguration key="configuration" allowsInlineMediaPlayback="YES">
|
||||
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" audio="YES" video="YES"/>
|
||||
<wkPreferences key="preferences"/>
|
||||
</wkWebViewConfiguration>
|
||||
</wkWebView>
|
||||
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="bottom" barStyle="black" id="3">
|
||||
<rect key="frame" x="0.0" y="436" width="320" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
|
@@ -15,6 +15,9 @@
|
||||
https://github.com/wordpress-mobile/WordPress-iOS/blob/8ff4b5b18c638f6b592018f277616db2734de2cb/WordPress/Classes/Utility/WPWebViewController.m
|
||||
block回调: https://www.jianshu.com/p/d911cd16c100
|
||||
Xcode11-闪退错误Could not instantiate class named WKWebView https://www.bilibili.com/read/cv3184836/
|
||||
|
||||
iOS-手动添加限制-constraints https://blog.csdn.net/wang1514869032/article/details/52164199
|
||||
contstrait https://blog.csdn.net/jason_chen13/article/details/52869540
|
||||
*/
|
||||
|
||||
#import "Common.h"
|
||||
@@ -61,6 +64,41 @@
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
// 创建网页配置对象
|
||||
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
|
||||
// 创建设置对象
|
||||
WKPreferences *preference = [[WKPreferences alloc]init];
|
||||
// 最小字体大小 当将javaScriptEnabled属性设置为NO时,可以看到明显的效果
|
||||
preference.minimumFontSize = 0;
|
||||
// 设置是否支持javaScript 默认是支持的
|
||||
preference.javaScriptEnabled = YES;
|
||||
// 在iOS上默认为NO,表示是否允许不经过用户交互由javaScript自动打开窗口
|
||||
preference.javaScriptCanOpenWindowsAutomatically = YES;
|
||||
config.preferences = preference;
|
||||
// 是使用h5的视频播放器在线播放, 还是使用原生播放器全屏播放
|
||||
config.allowsInlineMediaPlayback = YES;
|
||||
// 设置视频是否需要用户手动播放 设置为NO则会允许自动播放
|
||||
config.requiresUserActionForMediaPlayback = YES;
|
||||
// 设置是否允许画中画技术 在特定设备上有效
|
||||
config.allowsPictureInPictureMediaPlayback = YES;
|
||||
|
||||
self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:config];
|
||||
|
||||
// self.webView = [[WKWebView alloc] init];
|
||||
// self.view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self.view addSubview:_webView];
|
||||
|
||||
NSDictionary *dic = @{
|
||||
@"webView":self.webView
|
||||
};
|
||||
|
||||
NSString *vfl = @"V:|-0-[webView]-44-|"; // 上0, 下44
|
||||
NSString *vfl1 = @"H:|-0-[webView]-0-|"; // 左右为0
|
||||
_webView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
||||
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:vfl options:0 metrics:nil views:dic]];
|
||||
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:vfl1 options:0 metrics:nil views:dic]];
|
||||
|
||||
// 加了这一句 delegate才有用 didStartProvisionalNavigation !!!
|
||||
self.webView.navigationDelegate = self;
|
||||
|
||||
|
Reference in New Issue
Block a user