gpt4 book ai didi

swift osx webview 输入类型 = 文本不起作用

转载 作者:行者123 更新时间:2023-11-30 12:26:09 24 4
gpt4 key购买 nike

我以编程方式创建了窗口和 webview。

enter image description here

所有按钮、单选按钮均正常单击。但如果我点击输入并想要输入文本,它就不会点击。光标发生变化,但焦点不在输入中。键盘不打字。输入上的右键工作正常,我可以在其中粘贴文本。

//
// WindowCommand.swift
// DeskAlerts
//
// Created by mihail on 26/04/2017.
// Copyright © 2017 Toolbarstudio Inc. All rights reserved.
//

import Foundation
import Cocoa
import SINQ
import WebKit
extension NSCoder {
class func empty() -> NSCoder {
let data = NSMutableData()
let archiver = NSKeyedArchiver(forWritingWith: data)
archiver.finishEncoding()
return NSKeyedUnarchiver(forReadingWith: data as Data)
}
}



class WindowCommand:NSViewController, WebFrameLoadDelegate, WebUIDelegate, WebEditingDelegate, WebPolicyDelegate, WebDownloadDelegate, WebResourceLoadDelegate
{
var Coder: NSCoder?

var Window: NSWindow?

init() {
Coder = NSCoder.empty()
super.init(coder: Coder!)!
InitParentWindow()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func InitParentWindow()
{
let rect = NSRect.init(x: 0.0, y: 0.0, width: 500.0 , height: 500.0)
Window = NSWindow(contentRect: rect , styleMask: NSWindowStyleMask.borderless, backing: NSBackingStoreType.retained, defer: false, screen: MainScreen)


Window?.isOpaque = true
Window?.backgroundColor = NSColor.clear
Window?.hasShadow = false
Window?.isReleasedWhenClosed = true
Window?.acceptsMouseMovedEvents = true
Window?.allowsConcurrentViewDrawing = true
Window?.ignoresMouseEvents = false
Window?.isDocumentEdited = true
Window?.level = Int(CGWindowLevelForKey(.maximumWindow))
Window?.makeKeyAndOrderFront(self)
Window?.contentViewController = self
}

func Close()
{
Window?.close()
}


override func viewDidLoad() {
super.viewDidLoad()


let preferences = WebPreferences()
preferences.allowsAirPlayForMediaPlayback = true
preferences.allowsAnimatedImageLooping = true
preferences.allowsAnimatedImages = true
preferences.arePlugInsEnabled = true
preferences.autosaves = true
preferences.cacheModel = WebCacheModel.documentBrowser
preferences.isJavaEnabled = true
preferences.isJavaScriptEnabled = true
preferences.javaScriptCanOpenWindowsAutomatically = true
preferences.loadsImagesAutomatically = true
preferences.privateBrowsingEnabled = false
preferences.shouldPrintBackgrounds = false
preferences.tabsToLinks = false
preferences.usesPageCache = false
preferences.suppressesIncrementalRendering = true

self.view.frame = NSRect.init(x: 0, y: 0, width: 500, height: 500)
CaptionBrowser = WebView.init(frame: NSRect.init(x: 0, y: 0, width: 500, height: 500)
let nillvalue:WebView? = nil
if (CaptionBrowser != nillvalue)
{
CaptionBrowser?.uiDelegate = self
CaptionBrowser?.frameLoadDelegate = self
CaptionBrowser?.editingDelegate = self
CaptionBrowser?.policyDelegate = self
CaptionBrowser?.resourceLoadDelegate = self
CaptionBrowser?.downloadDelegate = self
CaptionBrowser?.windowScriptObject.setValue(HtmlInteropClass(data: Alert!, owner: self), forKey: "external")
CaptionBrowser?.preferences = preferences
self.view.addSubview(CaptionBrowser!, positioned: NSWindowOrderingMode.above, relativeTo: nil)


var url = NSURL(string: (ParentWindowParams?.captionhref)!)
CaptionBrowser?.mainFrame.load(URLRequest.init(url: (url! as URL) as URL))



let mainbrowserwidth = 480

let mainbrowserheight = 150






MainBrowser = WebView.init(frame: CGRect(x:10 ,y:150, width:480 ,height:150))
MainBrowser?.uiDelegate = self
MainBrowser?.frameLoadDelegate = self
MainBrowser?.editingDelegate = self
MainBrowser?.policyDelegate = self
MainBrowser?.resourceLoadDelegate = self
MainBrowser?.downloadDelegate = self
MainBrowser?.preferences = preferences
MainBrowser?.windowScriptObject.setValue(HtmlInteropClass(data: Alert!, owner: self), forKey: "external")

self.view.addSubview(MainBrowser!, positioned: NSWindowOrderingMode.above, relativeTo: CaptionBrowser)

let filePath = Bundle.main.path(forResource: "test", ofType: "html", inDirectory: "Resources")
url = NSURL(string: filePath!)
MainBrowser?.mainFrame.load(URLRequest.init(url: url! as URL))


//url = NSURL(string: Alerthref!)
//MainBrowser?.mainFrame.load(URLRequest.init(url: url! as URL))
}
}

func webView(_ sender: WebView!, createWebViewWith request: URLRequest!) -> WebView! {
return sender
}

func webView(_ webView: WebView!, decidePolicyForNavigationAction actionInformation: [AnyHashable : Any]!, request: URLRequest!, frame: WebFrame!, decisionListener listener: WebPolicyDecisionListener!)
{

listener.use()


}

func webView(_ webView: WebView!, decidePolicyForNewWindowAction actionInformation: [AnyHashable : Any]!, request: URLRequest!, newFrameName frameName: String!, decisionListener listener: WebPolicyDecisionListener!) {

listener.use()

}

func webView(_ sender: WebView!, runJavaScriptAlertPanelWithMessage message: String!, initiatedBy frame: WebFrame!) {
print(message)
}
func webView(_ sender: WebView!, runJavaScriptTextInputPanelWithPrompt prompt: String!, defaultText: String!, initiatedBy frame: WebFrame!) -> String! {


return ""
}

override func loadView() {
super.loadView()
}

override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}


}

最佳答案

发现一个麻烦。Window = NSWindow(contentRect: rect , styleMask: NSWindowStyleMask.borderless, backing: NSBackingStoreType.retained, defer: false, screen: MainScreen)

如果我创造属性(property)styleMask: NSWindowStyleMask.borderless输入不可用。

关于swift osx webview 输入类型 = 文本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44196204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com