1
我正在使用以下Swift代码将新的WKWebView加载到自定义视图对象中,为Mac OS App创建最小的WebKit浏览器。窗口大小问题
下面的代码行创建web视图以填充customView窗口的大小:
VAR theWebView:WKWebView = WKWebView(帧:self.customView.frame)
当你运行应用程序的网页加载正确,以填补窗口,但是如果窗口调整大小的网页不调整窗口。
我已经在界面生成器中的自定义视图对象中添加了约束,并相信此对象正确调整大小,但似乎WKWebView未调整以填充自定义视图?
请参阅下面的附加屏幕截图。
任何想法欢迎。
进口可可进口的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 } }