美文网首页
SwiftUI—创建两层嵌套的滚动视图

SwiftUI—创建两层嵌套的滚动视图

作者: anny_4243 | 来源:发表于2020-07-16 11:25 被阅读0次

    原文链接:https://github.com/fzhlee/SwiftUI-Guide#-%E7%AC%AC12%E8%8A%82scrollview-verticalandhorizontal-

    本节课将创建一个两层嵌套的滚动视图,处于外层的滚动视图允许垂直滚动,而处于内层的滚动视图,只允许水平滚动。

    示例代码:

    struct ContentView : View {
    
        var body: some View {
            ScrollView(.vertical, showsIndicators: false) {
                VStack(alignment: HorizontalAlignment.leading, spacing: 20){
    
                    Text("Overview")
                    .font(.system(size: 48))
                    .padding(10)
                    Text("With the power of Xcode, the ease of Swift, and the revolutionary features of cutting-edge Apple technologies, you have the freedom to create your most innovative apps ever.\nSwiftUI provides views, controls, and layout structures for declaring your app's user interface. The framework provides event handlers for delivering taps, gestures, and other types of input to your app, and tools to manage the flow of data from your app's models down to the views and controls that users will see and interact with.")
                    .lineLimit(nil)
                    .frame(width: 300, height: 350, alignment: .topLeading)
                    .padding(10)
                    
                    ScrollView(.horizontal, showsIndicators: true) {
                        HStack(alignment:.center, spacing: 20){
    
                            Image("iPhone")
                                .resizable()
                                .frame(width: 189, height: 350, alignment: .center)
    
                            Image("iPhoneSerial")
                                .resizable()
                                .frame(width: 518, height: 350, alignment: .center)
    
                            Image("iPhone")
                                .resizable()
                                .frame(width: 189, height: 350, alignment: .center)
                        }
                    }
                    .background(Color.orange)
                    .padding(10)
                }
            }
            .background(Color.orange)
            .padding(10)
            .navigationBarTitle(Text("ScrollView"))
        }
    }
    

    相关文章

      网友评论

          本文标题:SwiftUI—创建两层嵌套的滚动视图

          本文链接:https://www.haomeiwen.com/subject/hzfphktx.html