SwiftUI 匹配内联标题

当视图滚动到屏幕外时,将任何 SwiftUI Text 视图过渡到内联导航栏标题,就像在 Apple 的 TV 和 TestFlight iOS 应用中看到的效果一样。

示例

struct ContentView: View {
    
    @Namespace var namespace
    
    var body: some View {
        NavigationView {
            ScrollView {
                VStack(alignment: .leading) {
                    MatchedTitle("For All Mankind", namespace: namespace) {
                        $0
                            .font(.largeTitle)
                            .fontWeight(.bold)
                            .padding()
                    }

                    // Other content…
                }
            }
            .matchedInlineTitle(in: namespace)
            // Other view modifiers, including `Toolbar` can be used…
        }
    }
}

Screenshots

命名和命名空间约定遵循 Swift 现有的 .matchedGeometryEffect 视图修饰符。

MatchedTitle 视图可以使用任何 StringSubStringLocalizedStringKey 初始化,使用与 SwiftUI Text 类似的参数,并且它提供了对创建的 Text 视图的可选自定义。

.matchedInlineTitle 修饰符必须在 ScrollView 上使用,并强制导航栏标题显示模式为 inline

最低要求

许可

此库根据 MIT 许可发布。 有关更多信息,请参阅 LICENSE 文件。