WKWebView apparently has a bug prior to 10.12 so it can't be created via a nib.

This commit is contained in:
Kelvin Sherlock 2021-05-29 22:15:32 -04:00
parent e18aea7249
commit 9f38f2972a
2 changed files with 14 additions and 17 deletions

View File

@ -1,16 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
<plugIn identifier="com.apple.WebKit2IBPlugin" version="15705"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="CheatSheetWindowController">
<connections>
<outlet property="_webView" destination="Yc9-xA-jWX" id="rsd-1e-HPk"/>
<outlet property="webView" destination="Yc9-xA-jWX" id="EE3-gk-f71"/>
<outlet property="window" destination="QvC-M9-y7g" id="U2v-sN-OzH"/>
</connections>
</customObject>
@ -23,19 +19,6 @@
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="640" height="640"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<wkWebView hidden="YES" wantsLayer="YES" fixedFrame="YES" allowsLinkPreview="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Yc9-xA-jWX">
<rect key="frame" x="0.0" y="0.0" width="640" height="640"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<wkWebViewConfiguration key="configuration">
<audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
<wkPreferences key="preferences" javaScriptCanOpenWindowsAutomatically="NO"/>
</wkWebViewConfiguration>
<connections>
<outlet property="navigationDelegate" destination="-2" id="1WW-1B-FdZ"/>
</connections>
</wkWebView>
</subviews>
</view>
<connections>
<outlet property="delegate" destination="-2" id="u4H-aq-RE2"/>

View File

@ -27,6 +27,20 @@
- (void)windowDidLoad {
[super windowDidLoad];
if (!_webView) {
WKWebView *webView;
NSWindow *window = [self window];
CGRect frame = [[window contentView] frame];
webView = [WKWebView new];
[webView setFrame: frame];
[webView setNavigationDelegate: self];
[[window contentView]addSubview: webView];
_webView = webView;
}
[_webView setHidden: YES];
NSBundle *bundle = [NSBundle mainBundle];
NSURL *url = [bundle URLForResource: @"CheatSheet" withExtension: @"html"];