swiftui_SwiftUI中的DisclosureGroup
swiftui
Recently introduced at WWDC 2020, this behavior could be recreated with StackView in UIKit, but the process of making it is a little tedious. DisclosureGroup
is able to address that with a few lines of code.
最近在WWDC 2020上引入了此行为,可以使用UIKit中的StackView重新创建此行为,但是制作过程有点繁琐。 DisclosureGroup
能够用几行代码来解决这个问题。
“A view that shows or hides another content view, based on the state of a disclosure control.” — Apple’s documentation
“基于公开控件的状态,显示或隐藏另一个内容视图的视图。” — Apple的文档
先决条件 (Prerequisites)
To follow along with this tutorial, you’ll need some basic knowledge in:
要继续学习本教程,您将需要一些基本知识:
- Swift Swift
- At least Xcode 12+ 至少Xcode 12+
Note: This only supports iOS 14+.
注意:这仅支持iOS 14+。
披露组 (DisclosureGroup)
You will first have to create a State
to control the dropdown, but rest assured that the rest of it will be taken care of. Here, you will be creating a dropdown menu that consists of food items and drinks.
您首先必须创建一个State
来控制下拉菜单,但是请放心,其余部分将得到处理。 在这里,您将创建一个包含食品和饮料的下拉菜单。
So you will be needing at least three States
, with each of them attached to its respective dropdown:
因此,您将至少需要三个States
,每个州都附有各自的下拉列表:
@State private var topExpanded: Bool = false
@State private var foodExpanded: Bool = false
@State private var drinkExpanded: Bool = false
Next, use DisclosureGroup
:
接下来,使用DisclosureGroup
:
Voila:
瞧:
翻译自: https://medium.com/better-programming/disclosuregroup-in-swiftui-868739aedf77
swiftui
上一篇: hessian——序列化
下一篇: python os