我正在尝试在导航栏的尾部创建一个自定义菜单(基于editMode的动态菜单)。我需要3个按钮在“查看”模式和只有一个在“编辑”模式。
问题是我不能将按钮向右对齐,如下所示:


如你所见,“完成”按钮在左边。
我尝试添加Spacers(),但没有成功。
.navigationBarItems(
leading: BackButton(label: "") {
self.presentation.wrappedValue.dismiss()
},
trailing:
HStack {
if self.mode?.wrappedValue == .inactive {
HStack(alignment: .center, spacing: 20) {
Button(action: {
////////
}) {
Image(systemName: "trash")
.imageScale(.large)
}
////////
Button(action: {
}) {
Image(systemName: "square.and.arrow.up")
.imageScale(.large)
}
CustomEditButton() {
////////
}
}
} else {
HStack {
CustomEditButton() {
/////
}
}
}
}
)发布于 2020-06-07 05:33:23
同样的问题。noticed ()在条件语句内部或外部都不起作用。我注意到,当从NavigationLink屏幕弹回视图时,对齐是固定的/正确的。无论如何,我使用不透明使其在我这一端工作,这取决于驱动更改的条件。在您的情况下,解决方法可能如下所示:
.navigationBarItems(
leading: BackButton(label: "") {
self.presentation.wrappedValue.dismiss()
},
trailing:
ZStack {
HStack(alignment: .center, spacing: 20) {
Button(action: {
////////
}) {
Image(systemName: "trash")
.imageScale(.large)
}
Button(action: {
////////
}) {
Image(systemName: "square.and.arrow.up")
.imageScale(.large)
}
CustomEditButton() {
////////
}
}
.opacity((self.mode?.wrappedValue == .inactive) ? 1.0 : 0.0)
HStack {
CustomEditButton() {
/////
}
}
.opacity((self.mode?.wrappedValue == .inactive) ? 0.0 : 1.0)
}
)https://stackoverflow.com/questions/60520768
复制相似问题