From 8b3f6d639cad1da8e411387b7c2bb29e52675a03 Mon Sep 17 00:00:00 2001 From: Tom Solchan Ahn Date: Wed, 8 Jan 2025 16:02:13 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]=20BezierWindow=20=EB=B0=A9=EC=96=B4?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/BezierSwift/BezierWindow.swift | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Sources/BezierSwift/BezierWindow.swift b/Sources/BezierSwift/BezierWindow.swift index 35bc9698..d8712c61 100644 --- a/Sources/BezierSwift/BezierWindow.swift +++ b/Sources/BezierSwift/BezierWindow.swift @@ -27,11 +27,27 @@ final class BezierWindow: UIWindow { } override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { - let hitView = super.hitTest(point, with: event) + guard + BezierSwift.shared.allowHitTest, + let hitView = super.hitTest(point, with: event), + let rootView = rootViewController?.view + else { return nil } - guard BezierSwift.shared.allowHitTest else { return nil } - - return (hitView == self || self.rootViewController?.view == hitView) ? nil : hitView + // NOTE: iOS 18, Xcode 16 이상 버전을 사용할 때, hitTest 결과가 다르게 나옵니다. + // view -> subView 로 이어지는 hitTest 플로우가 역으로 다시 UIHostingViewController 의 hitTest로 가는 상황이 생깁니다. + // https://forums.developer.apple.com/forums/thread/762292 + // by Tom 25.01.08 + if #available(iOS 18, *) { + for subview in rootView.subviews.reversed() { + let convertedPoint = subview.convert(point, from: rootView) + if subview.hitTest(convertedPoint, with: event) != nil { + return hitView + } + } + return nil + } else { + return (hitView == self || rootView == hitView) ? nil : hitView + } } }