List 迅捷-i';I’我想删除“之间的空格”;“后退按钮”;还有,导航巴蒂尔
我想删除我的后退按钮(“Rezept hinzufügen”)和导航按钮(“Suche”)之间的空格。。。我不明白为什么会有这个空间,所以我需要你的群体智能。:) 我试了什么List 迅捷-i';I’我想删除“之间的空格”;“后退按钮”;还有,导航巴蒂尔,list,swiftui,uisearchbar,List,Swiftui,Uisearchbar,我想删除我的后退按钮(“Rezept hinzufügen”)和导航按钮(“Suche”)之间的空格。。。我不明白为什么会有这个空间,所以我需要你的群体智能。:) 我试了什么 使用ZStack时,可能以前有NavigationView正在处理此错误 添加垫片() 重新创建整个视图 现在我卡住了 我想最简单的方法就是用视频向你展示我的问题 这是我的密码 import SwiftUI extension UIApplication { func endEditing(_force : B
import SwiftUI
extension UIApplication
{
func endEditing(_force : Bool)
{
self.windows
.filter{$0.isKeyWindow}
.first?
.endEditing(_force)
}
}
struct ResignKeyboardOnDragGesture: ViewModifier
{
var gesture = DragGesture().onChanged{_ in UIApplication.shared.endEditing(_force: true)}
func body(content: Content) -> some View
{
content.gesture(gesture)
}
}
extension View
{
func resignKeyboardOnDragGesture() -> some View
{
return modifier(ResignKeyboardOnDragGesture())
}
}
/*
Zutaten pflegen Button, zum hinzufügen von Zutaten zu einem Rezept.
**/
struct RecipeIngredientsView: View {
let myArray = ["Dennis", "Tessa", "Peter", "Anna", "Tessa", "Klaus", "Xyan", "Zuhau", "Clown", "Brot", "Bauer"]
@State private var searchText = ""
@State private var showCancelButton: Bool = false
var body: some View {
NavigationView
{
VStack
{
HStack
{
HStack
{
Image(systemName: "magnifyingglass")
TextField("Suche", text: $searchText, onEditingChanged: { isEditing in self.showCancelButton = true}, onCommit: {
print("onCommit")
}).foregroundColor(.primary)
Button(action: {
self.searchText = searchText
}){
Image(systemName: "xmark.circle.fill").opacity(searchText == "" ? 0 : 1)
}
}.padding(EdgeInsets(top: 8, leading: 6, bottom: 8, trailing: 6))
.foregroundColor(.secondary)
.background(Color(.secondarySystemBackground))
.cornerRadius(10.0)
if showCancelButton {
Button("Abbrechen")
{
UIApplication.shared.endEditing(_force: true)
self.searchText = ""
self.showCancelButton = false
}
.foregroundColor(Color(.systemBlue))
}
}
.padding(.horizontal)
.navigationBarHidden(showCancelButton)
//Gefilterte Liste der Namen aus meinem Array
List {
ForEach(myArray.filter{$0.hasPrefix(searchText) || searchText == ""}, id:\.self)
{
searchText in Text(searchText)
}
}
.navigationBarTitle(Text("Suche"))
.resignKeyboardOnDragGesture()
}
}
}
}
谢谢你的帮助!
:-)只需删除冗余的
NavigationView
-在同一视图层次结构中只需要一个,显然在父视图中已经有一些
struct RecipeIngredientsView: View {
let myArray = ["Dennis", "Tessa", "Peter", "Anna", "Tessa", "Klaus", "Xyan", "Zuhau", "Clown", "Brot", "Bauer"]
@State private var searchText = ""
@State private var showCancelButton: Bool = false
var body: some View {
NavigationView // << remove this one !!
{
struct RecipeIngredientsView:视图{
让我的数组=[“丹尼斯”、“泰莎”、“彼得”、“安娜”、“泰莎”、“克劳斯”、“西安”、“祖豪”、“小丑”、“布罗特”、“鲍尔”]
@国家私有var searchText=“”
@国家私有var showCancelButton:Bool=false
var body:一些观点{
导航视图//谢谢,很简单..xD