NSSplitView:自定义双击处理程序

时间:2019-07-15 19:16:48

标签: swift cocoa divider nssplitview

我试图找出如何检测双击NSSplitView分隔符的方法。在我看来,分隔线既不暴露于NSSplitViewDelegate,也不暴露于NSSplitViewController。

到目前为止,我发现分隔符是NSSplitDividerView的一个实例,它是一个私有类,因此无法扩展或子类化。

您能让我回到正确的调查轨道上吗?

谢谢。

2 个答案:

答案 0 :(得分:1)

可能的解决方案是子类NSSplitView并覆盖mouseDown(with:)。检查事件的位置是否在子视图之间。

override func mouseDown(with event: NSEvent) {
    if event.clickCount == 2 {
        let location = self.convert(event.locationInWindow, from: nil)
        if location.x > NSMaxX(self.arrangedSubviews[0].frame) && location.x < NSMinX(self.arrangedSubviews[1].frame) {
            Swift.print("doubleclick")
            return
        }
    }
    super.mouseDown(with: event)
}

答案 1 :(得分:0)

我很确定您可以在拆分视图的委托对象中实现file_name = "index.html" endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net' bucket_name = "cmadden-cc-tutorial" import boto3 resource = boto3.resource( 's3', aws_access_key_id = credentials["cos_hmac_keys"]['access_key_id'], aws_secret_access_key = credentials["cos_hmac_keys"]["secret_access_key"], endpoint_url = endpoint, ) import os directory = os.getcwd() html_path = directory + "/" + file_name f = open(html_path, "r") resource.Bucket(name=bucket_name).put_object(Key= file_name, Body=f.read()) 方法,返回optional func splitView(_ splitView: NSSplitView, shouldCollapseSubview subview: NSView, forDoubleClickOnDividerAt dividerIndex: Int) -> Bool,然后执行您想要的任何自定义操作。

相关问题