次の Swift コードを使用して、新しい WKWebView をカスタム ビュー オブジェクトにロードする、Mac OS アプリ用の最小限の WebKit ブラウザーを作成しています。
次のコード行は、customView ウィンドウのサイズを満たす Web ビューを作成します。
var theWebView:WKWebView = WKWebView(frame:self.customView.frame)
アプリを実行すると、Web ページがウィンドウいっぱいに正しく読み込まれますが、ウィンドウのサイズが変更された場合、Web ページはウィンドウに合わせてサイズ変更されません。
インターフェイス ビルダーでカスタム ビュー オブジェクトに制約を追加しましたが、このオブジェクトのサイズは正しく変更されていると思いますが、WKWebView がカスタム ビューを埋めるように調整されていないようです。
以下の添付のスクリーンショットを参照してください。
どんなアイデアでも大歓迎です。
import Cocoa import WebKit
@NSApplicationMain クラス AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow! @IBOutlet weak var customView: NSView! func applicationDidFinishLaunching(aNotification: NSNotification) { // Insert code here to initialize your application //create a URL for the path var url = NSURL(string:"http://www.google.com/") //create a request for the URL var request = NSURLRequest(URL:url!) //create the WKWebView and set the size to match //the window's full view var theWebView:WKWebView = WKWebView(frame:self.customView.frame) //have the web view load the page theWebView.loadRequest(request) //add the web view to the main window self.customView.addSubview(theWebView) } func applicationWillTerminate(aNotification: NSNotification) { // Insert code here to tear down your application } }