Swift3 将相邻跟踪区域视为一个相邻区域

Swift3 将相邻跟踪区域视为一个相邻区域,swift3,core-animation,nstrackingarea,Swift3,Core Animation,Nstrackingarea,当鼠标离开窗口的标题或contentview时,我试图呈现一个标题/无标题窗口的UI,但当鼠标从一个窗口移动到另一个窗口时,我不会这样做;本质上,将两个跟踪区域作为一个功能(我采用了这个方法,因为我不知道如何在标题视图隐藏时创建单个区域): 此外,“关闭”按钮上还有一个跟踪矩形,仅在结束时显示。无论如何,从我的跟踪器输出中,我看到“问题-鼠标悬停”窗口从标题下方到上方: view entered updateTitleBar **view entered** view exited update

当鼠标离开窗口的标题或contentview时,我试图呈现一个标题/无标题窗口的UI,但当鼠标从一个窗口移动到另一个窗口时,我不会这样做;本质上,将两个跟踪区域作为一个功能(我采用了这个方法,因为我不知道如何在标题视图隐藏时创建单个区域):

此外,“关闭”按钮上还有一个跟踪矩形,仅在结束时显示。无论如何,从我的跟踪器输出中,我看到“问题-鼠标悬停”窗口从标题下方到上方:

view entered
updateTitleBar
**view entered**
view exited
updateTitleBar
title entered
updateTitleBar
title exited
请注意,为什么我会得到第二个视图输入事件(视图输入),但是移出视图和移动到相邻标题上都会触发一个updateTilebar()调用,该调用在视觉上是断断续续的-到目前为止还没有通过动画进行纠正:

fileprivate func docIconToggle() {
    let docIconButton = panel.standardWindowButton(.documentIconButton)

    if settings.autoHideTitle.value == false || mouseOver {
        if let doc = self.document {
            docIconButton?.image = (doc as! Document).displayImage
        }
        else
        {
            docIconButton?.image = NSApp.applicationIconImage
        }
        docIconButton?.isHidden = false
        self.synchronizeWindowTitleWithDocumentName()
    }
    else
    {
        docIconButton?.isHidden = true
    }
}

@objc func updateTitleBar(didChange: Bool) {
    if didChange {
        Swift.print("updateTitleBar")
        if settings.autoHideTitle.value == true && !mouseOver {
            NSAnimationContext.runAnimationGroup({ (context) -> Void in
                context.duration = 1.0
                panel.animator().titleVisibility = NSWindowTitleVisibility.hidden
                panel.animator().titlebarAppearsTransparent = true
                panel.animator().styleMask.formUnion(.fullSizeContentView)
            }, completionHandler: {
                self.docIconToggle()
            })
        } else {
            NSAnimationContext.runAnimationGroup({ (context) -> Void in
                context.duration = 1.0
                panel.animator().titleVisibility = NSWindowTitleVisibility.visible
                panel.animator().titlebarAppearsTransparent = false
                panel.animator().styleMask.formSymmetricDifference(.fullSizeContentView)
            }, completionHandler: {
                self.docIconToggle()
            })
        }
    }
}
所以我的问题是,当区域相邻时,如何推迟行动

他们(标题栏和内容视图)不是兄弟姐妹,所以不认为hitTest()是可行的,但基本上,如果我能知道我是否正在移动到相邻的跟踪区域,我希望这是不可行的


任何关于动画为什么不起作用的帮助都是一个加号。

不是正确的答案,但如果您知道相邻视图的rect,您可以使用事件的位置来探测是否要忽略相邻视图之间的移动:

override func mouseExited(with theEvent: NSEvent) {
    let hideTitle = (doc?.settings.autoHideTitle.value == true)
    let location : NSPoint = theEvent.locationInWindow

    switch theEvent.trackingNumber {
    case closeTrackingTag:
        Swift.print("close exited")
        closeButton?.image = nullImage
        break

    default:
        let vSize = self.window?.contentView?.bounds.size

        //  If we exit to the title bar area we're still "inside"
        //  and visa-versa, leaving title to content view.
        if theEvent.trackingNumber == titleTrackingTag, let tSize = titleView?.bounds.size {
            if location.x >= 0.0 && location.x <= (vSize?.width)! && location.y < ((vSize?.height)! + tSize.height) {
                Swift.print("title -> view")
                return
            }
        }
        else
        if theEvent.trackingNumber == viewTrackingTag {
            if location.x >= 0.0 && location.x <= (vSize?.width)! && location.y > (vSize?.height)! {
                Swift.print("view -> title")
                return
            }
        }

        mouseOver = false
        updateTranslucency()

        if hideTitle {
            updateTitleBar(didChange: true)
        }

        Swift.print(String(format: "%@ exited",
                           (theEvent.trackingNumber == titleTrackingTag
                            ? "title" : "view")))
    }
}
覆盖函数鼠标退出(theEvent:NSEvent){
let hideTitle=(doc?.settings.autoHideTitle.value==true)
让位置:NSPoint=theEvent.locationInWindow
切换事件跟踪编号{
案例关闭跟踪标签:
Swift.打印(“关闭退出”)
closeButton?.image=nullImage
打破
违约:
让vSize=self.window?.contentView?.bounds.size
//如果我们退出到标题栏区域,我们仍然“在里面”
//反之亦然,将标题留给内容视图。
如果event.trackingNumber==titleTrackingTag,则让tSize=titleView?.bounds.size{
如果location.x>=0.0&&location.x=0.0&&location.x(vSize?.height){
Swift.print(“视图->标题”)
返回
}
}
mouseOver=false
UpdateTranslucy()
如果隐藏{
updateTitleBar(didChange:true)
}
Swift.print(字符串(格式:“%@已退出”,
(theEvent.trackingNumber==标题跟踪标记
?“标题”:“视图”))
}
}
override func mouseExited(with theEvent: NSEvent) {
    let hideTitle = (doc?.settings.autoHideTitle.value == true)
    let location : NSPoint = theEvent.locationInWindow

    switch theEvent.trackingNumber {
    case closeTrackingTag:
        Swift.print("close exited")
        closeButton?.image = nullImage
        break

    default:
        let vSize = self.window?.contentView?.bounds.size

        //  If we exit to the title bar area we're still "inside"
        //  and visa-versa, leaving title to content view.
        if theEvent.trackingNumber == titleTrackingTag, let tSize = titleView?.bounds.size {
            if location.x >= 0.0 && location.x <= (vSize?.width)! && location.y < ((vSize?.height)! + tSize.height) {
                Swift.print("title -> view")
                return
            }
        }
        else
        if theEvent.trackingNumber == viewTrackingTag {
            if location.x >= 0.0 && location.x <= (vSize?.width)! && location.y > (vSize?.height)! {
                Swift.print("view -> title")
                return
            }
        }

        mouseOver = false
        updateTranslucency()

        if hideTitle {
            updateTitleBar(didChange: true)
        }

        Swift.print(String(format: "%@ exited",
                           (theEvent.trackingNumber == titleTrackingTag
                            ? "title" : "view")))
    }
}