gpt4 book ai didi

ios - 有没有办法在 SwiftUI 中创建下拉菜单/按钮?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:27:48 26 4
gpt4 key购买 nike

我想在 Xcode 11 Beta 1 中创建一个下拉菜单。但我还没有找到在 iOS 中实现它的方法。

我用.hidden函数试过了,找到了PullDownButton,但是不知道怎么设置

我已经创建了这个代码

struct SwiftUIView : View {
@State var array = true
@State var buttonTitle = "Zeige Deteils"

var body: some View {
VStack {
VStack {
Button(action: {
self.array.toggle()

}) {
Text(buttonTitle)
}


if array {
VStack(spacing: 1.0) {

Button(action: {
self.buttonTitle = "Schmelzpunkt"
self.array.toggle()
}) {
Text("Schmelzpunkt")
.color(.white)
.padding(.all)
}
.background(Color.blue)
Button(action: {
self.buttonTitle = "Instrumentelle Analytik"
self.array.toggle()
}) {
Text("Instrumentelle Analytik")
.color(.white)
.padding(.all)
}.background(Color.blue)
Button(action: {
self.buttonTitle = "Aussehen"
self.array.toggle()
}) {
Text("Aussehen")
.color(.white)
.padding(.all)
}.background(Color.blue)

}
.padding(.top)
}
}
}
}

但找不到一个是为隐藏按钮的“弹出”设置动画并希望主按钮留在其位置

最佳答案

在 SwiftUI 2.0 (iOS 14+) 中,您可以使用 Menu 制作下拉菜单。

Menu {
Button {
// do something
} label: {
Text("Linear")
Image(systemName: "arrow.down.right.circle")
}
Button {
// do something
} label: {
Text("Radial")
Image(systemName: "arrow.up.and.down.circle")
}
} label: {
Text("Style")
Image(systemName: "tag.circle")
}

关于ios - 有没有办法在 SwiftUI 中创建下拉菜单/按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56513339/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com