我正在使用 SwiftUI 创建一个项目,并希望向导航栏添加一个搜索栏,就像本机设置应用程序、邮件应用程序等中存在的那样。
我已经尝试了一些东西,但不能完全让它工作。以下代码运行良好,但即使我包含navigationController.navigationItem.hidesSearchBarWhenScrolling = false
. 任何帮助,将不胜感激。
//
// ContentView.swift
// SwiftUITest
//
// Created by me on 1/7/20.
// Copyright © 2020 me. All rights reserved.
//
import SwiftUI
struct HomeView: View {
var body: some View {
ScrollView {
HStack {
Spacer(minLength: 0)
Text("Hello World")
Spacer(minLength: 0)
}
}
.navigationBarTitle(Text("Search"))
}
}
struct SecondView: View {
var body: some View {
return Text("Second View")
}
}
struct CustomUIViewControllerRepresentation: UIViewControllerRepresentable {
typealias UIViewControllerType = UINavigationController
func makeUIViewController(context: …
Run Code Online (Sandbox Code Playgroud)