手势开始处理逻辑
This commit is contained in:
parent
e7549803b6
commit
d3c5004797
@ -54,6 +54,15 @@ struct SearchView: View {
|
|||||||
.opacity(showSearchResult && searchModel.dramaGroups.isEmpty ? 1 : 0)
|
.opacity(showSearchResult && searchModel.dramaGroups.isEmpty ? 1 : 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.background(
|
||||||
|
GestureObserver {
|
||||||
|
// 当检测到系统返回手势时调用
|
||||||
|
if isFocused {
|
||||||
|
isFocused = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(width: 0, height: 0)
|
||||||
|
)
|
||||||
.navigationTitle("")
|
.navigationTitle("")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .principal) {
|
ToolbarItem(placement: .principal) {
|
||||||
@ -123,6 +132,42 @@ struct SearchDramaGroupView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct GestureObserver: UIViewControllerRepresentable {
|
||||||
|
var onGestureBegin: () -> Void
|
||||||
|
|
||||||
|
func makeUIViewController(context: Context) -> UIViewController {
|
||||||
|
let controller = UIViewController()
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if let nav = controller.navigationController,
|
||||||
|
let gesture = nav.interactivePopGestureRecognizer {
|
||||||
|
gesture.addTarget(context.coordinator, action: #selector(Coordinator.handleGesture(_:)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return controller
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIViewController, context: Context) { }
|
||||||
|
|
||||||
|
func makeCoordinator() -> Coordinator {
|
||||||
|
Coordinator(onGestureBegin: onGestureBegin)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Coordinator: NSObject {
|
||||||
|
var onGestureBegin: () -> Void
|
||||||
|
|
||||||
|
init(onGestureBegin: @escaping () -> Void) {
|
||||||
|
self.onGestureBegin = onGestureBegin
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func handleGesture(_ gesture: UIScreenEdgePanGestureRecognizer) {
|
||||||
|
if gesture.state == .began {
|
||||||
|
onGestureBegin()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//#Preview {
|
//#Preview {
|
||||||
// SearchView()
|
// SearchView()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user