我正在尝试像苹果在他们的消息应用程序中所做的那样隐藏我的应用程序中的搜索栏:
我已经在SwiftUI中实现了UISearchBar:
struct SearchBar: UIViewRepresentable {
@Binding var text: String
class Coordinator: NSObject, UISearchBarDelegate {
@Binding var text: String
init(text: Binding<String>) {
_text = text
}
func searchBar(_: UISearchBar, textDidChange searchText: String) {
text = searchText
}
}
func makeCoordinator() -> SearchBar.Coordinator {
return Coordinator(text: $text)
}
func makeUIView(context: UIViewRepresentableContext<SearchBar>) -> UISearchBar {
let searchBar = UISearchBar(frame: .zero)
searchBar.delegate = context.coordinator
searchBar.searchBarStyle = .minimal
searchBar.placeholder = "Поиск по названию, дедлайну или описанию"
return searchBar
}
func updateUIView(_ uiView: UISearchBar, context _: UIViewRepresentableContext<SearchBar>) {
uiView.text = text
}
}
我如何在SwiftUI中实现隐藏和隐藏动画?