【发布时间】:2014-12-17 07:00:28
【问题描述】:
我正在为 Mac OS 应用程序创建一个最小的 WebKit 浏览器,使用以下 Swift 代码将新的 WKWebView 加载到自定义视图对象中。
以下代码行创建 web 视图以填充 customView 窗口的大小:
var theWebView:WKWebView = WKWebView(frame:self.customView.frame)
当您运行应用程序时,网页会正确加载以填满窗口,但是如果调整窗口大小,则网页不会随窗口调整大小。
我已在界面构建器中为自定义视图对象添加了约束,并认为该对象的大小调整正确,但 WKWebView 似乎没有调整以填充自定义视图?
请参阅下面的附加屏幕截图。
欢迎任何想法。
导入 Cocoa 导入 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 } }
【问题讨论】: