fix: title bar shows/hides based on window hover, not just top strip
- Remove 28pt overlay hover detection - Add .onHover to entire window content (ZStack) - Extract setWindowTitleBarVisible() helper function - Mouse enters window → show title bar, mouse leaves → hide
This commit is contained in:
parent
5a031a57ea
commit
ec8c3bd51c
@ -241,6 +241,15 @@ struct PlayerContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func setWindowTitleBarVisible(_ visible: Bool) {
|
||||||
|
guard let win = NSApplication.shared.windows.first(where: { $0.isVisible }) else { return }
|
||||||
|
win.titlebarAppearsTransparent = !visible
|
||||||
|
win.titleVisibility = visible ? .visible : .hidden
|
||||||
|
win.standardWindowButton(.closeButton)?.isHidden = !visible
|
||||||
|
win.standardWindowButton(.miniaturizeButton)?.isHidden = !visible
|
||||||
|
win.standardWindowButton(.zoomButton)?.isHidden = !visible
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack(alignment: .topLeading) {
|
ZStack(alignment: .topLeading) {
|
||||||
Color.black.ignoresSafeArea()
|
Color.black.ignoresSafeArea()
|
||||||
@ -318,6 +327,9 @@ struct PlayerContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onHover { hovering in
|
||||||
|
setWindowTitleBarVisible(hovering)
|
||||||
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
// 初始状态:标题栏完全隐藏(含红绿灯按钮)
|
// 初始状态:标题栏完全隐藏(含红绿灯按钮)
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||||
@ -337,28 +349,6 @@ struct PlayerContentView: View {
|
|||||||
hideTimer?.invalidate()
|
hideTimer?.invalidate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.overlay(alignment: .top) {
|
|
||||||
// 标题栏悬停检测:鼠标进入显示标题栏,退出隐藏
|
|
||||||
Color.clear
|
|
||||||
.frame(height: 28)
|
|
||||||
.contentShape(Rectangle())
|
|
||||||
.onHover { hovering in
|
|
||||||
guard let win = NSApplication.shared.windows.first(where: { $0.isVisible }) else { return }
|
|
||||||
if hovering {
|
|
||||||
win.titlebarAppearsTransparent = false
|
|
||||||
win.titleVisibility = .visible
|
|
||||||
win.standardWindowButton(.closeButton)?.isHidden = false
|
|
||||||
win.standardWindowButton(.miniaturizeButton)?.isHidden = false
|
|
||||||
win.standardWindowButton(.zoomButton)?.isHidden = false
|
|
||||||
} else {
|
|
||||||
win.titleVisibility = .hidden
|
|
||||||
win.titlebarAppearsTransparent = true
|
|
||||||
win.standardWindowButton(.closeButton)?.isHidden = true
|
|
||||||
win.standardWindowButton(.miniaturizeButton)?.isHidden = true
|
|
||||||
win.standardWindowButton(.zoomButton)?.isHidden = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
hideTimer?.invalidate()
|
hideTimer?.invalidate()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user