SwiftUI 2.0 matchedGeometryEffect 基础教程含源码

看完SwiftUI的新增功能后,引起我注意的一个功能是matchGeometryEffect。 这是一个新的SwiftUI效果,可以在两个视图之间插入位置和大小。 让我们看看我们能用它做什么。

WWDC教程

基础知识

matchedGeometryEffect

使用您提供的标识符和名称空间定义一组具有同步几何的视图。

func matchedGeometryEffect<ID>(id: ID, in namespace: Namespace.ID, properties: MatchedGeometryProperties= .frame, anchor: UnitPoint = .center, isSource: Bool = true) -> some View where ID : Hashable

使用教程

SwiftUI已经为我们内插视图的属性,而无需matchGeometryEffect。 在下面的示例中,我们可以使用轻击手势为矩形尺寸设置动画。

struct ContentView: View {
    @State private var isExpanded = false
    
    var body: some View {        
        RoundedRectangle(cornerRadius: 10)
            .foregroundColor(Color.pink)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章