按钮有一个奇怪的问题。所以我有一个NSViewController,里面有很多子视图。单击按钮时,顶部会添加带有单击手势和按钮的新NSView。但是我不能按任何一个,除非点击2秒然后释放,否则他们不会做出反应。我试过禁用持有人的手势,但它没有用。有什么建议吗?
答案 0 :(得分:0)
好吧,我们其他人都做了。就我而言,它适用于工作表中视图上的按钮,因此“很多子视图”不太可能。我的工作表视图控制器大约是100行。还在调试......
目前VC如下。 snp.makeConstraints调用适用于SnapKit(来自GitHub)
@objc
class ThreadEditSheetViewController: NSViewController {
/// The container for the graphics view
@IBOutlet var sheetView: NSView!
/// The information packet initialized by the invoking view controller
var info: ThreadEditInfo!
/// API
override func viewDidLoad() {
super.viewDidLoad()
}
/// API
override func viewWillAppear() {
guard let gvc = (try? self.bundleLoader(id: "GraphicsViewController")) as? GraphicsViewController else {
fatalUserAlert(error: AppError.UIConstructionFailure, message: "Can't find GraphicsViewController for ThreadEditSheetViewController")}
let gv = gvc.view
self.view.addSubview(gv)
// Spaces in title text move it left to avoid visual overlap with scroll bar. Don't know how to do it with
// constraints given the scrolling view
let done = makeButton(gvc: gvc, title: "done ", action: #selector(doneEditing(_:)))
done.snp.makeConstraints{ (make) in
make.top.equalTo(gv).offset(-5)
make.right.equalTo(gv).offset(-5)
}
let cancel = makeButton(gvc: gvc, title: "cancel", action: #selector(cancelEditing(_:)))
cancel.snp.makeConstraints{ (make) in
make.top.equalTo(gv).offset(-5)
make.left.equalTo(gv).offset(5)
}
self.view.becomeFirstResponder()
super.viewWillAppear()
return
}
func makeButton(gvc: NSViewController, title: String, action: Selector) -> NSButton {
let button = NSButton(title: title, target: self, action: action)
let gv = gvc.view
gv.addSubview(button)
button.backgroundColor = .clear
button.setButtonType(.momentaryChange)
button.isTransparent = true
return button
}
@objc
func doneEditing(_ sender: Any) {
self.dismissViewController(self)
}
@objc
func cancelEditing(_ sender: Any) {
self.dismissViewController(self)
}
}