SwiftUI:奇怪的行为ScrollView

问题描述 投票:0回答:2

[使用垂直和水平滚动时,看不到图像的左上角。但同时,右下角后还有一些空间。如何解决?

struct TestView: View {
    var body: some View {
        VStack(alignment: .leading) {
            ScrollView([.horizontal, .vertical]) {
                Image(systemName: "keyboard")
                    .resizable()
                    .frame(width:  500.0, height: 500.0)
            }.frame(width:  300.0, height: 300.0)
        }
    }
}
scrollview swiftui
2个回答
0
投票

您只需为滚动视图的内容添加偏移量

   var body: some View {
      VStack(alignment: .leading) {
          ScrollView([.horizontal, .vertical]) {
              Image(systemName: "keyboard")
                  .resizable()
                .frame(width:  500.0, height: 500.0).offset(x: 100, y: 100)
          }.frame(width:  300.0, height: 300.0)
      }
  }

0
投票

关于

struct TestView: View {
    var body: some View {
        ScrollView([.horizontal, .vertical]) {
            VStack {
                Spacer(minLength: 200)
                HStack {
                    Spacer(minLength: 200)
                    Image(systemName: "keyboard")
                        .resizable()
                        .frame(width: 300.0, height: 300.0)
                }
            }
        }
        .frame(width: 300.0, height: 300.0)
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.