我正在使用以下Swift代码为Mac OS App创建一个最小的WebKit浏览器,以将新的WKWebView加载到自定义视图对象中。
当我运行应用程序时,网页正确加载并填充窗口,但是如果调整窗口大小,则子视图不会随窗口大小调整。
非常感谢任何帮助。
import Cocoa
import WebKit
import AppKit
@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var customView: NSView!
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
var url = NSURL(string:"http://www.google.com/")
var request = NSURLRequest(URL:url!)
var theWebView:WKWebView = WKWebView(frame: customView.bounds)
self.customView.autoresizingMask = NSAutoresizingMaskOptions.ViewWidthSizable | NSAutoresizingMaskOptions.ViewHeightSizable
self.customView.addSubview(theWebView)
theWebView.loadRequest(request)
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}