【问题标题】:SwiftUI NavigationView not see ImageSwiftUI NavigationView 看不到图像
【发布时间】:2020-04-12 07:15:22
【问题描述】:

我有一个代码并制作了 NavigationLink 按钮,我编写了文本和图像,但我的图像看不到。请帮助我。

VStack{
        Image("Coachs")
            .resizable()
            .aspectRatio(contentMode: .fill)
            .frame(width: 370, height: 200)
            //.clipped()
            .cornerRadius(20.0)
        NavigationLink(destination: Text("Detail view here")){
            ZStack{
                Text("Press on me")
                    .foregroundColor(.white)
                    .font(.largeTitle)
                Image("Coachs")
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width: 370, height: 200)
                    //.clipped()
                    .cornerRadius(20.0)

            }


        }}

如果您看不懂,我会制作屏幕

【问题讨论】:

    标签: swift swiftui navigationlink


    【解决方案1】:

    好的,我查看了其他图像类型,试试这个,它应该可以工作:

        Image("IMG_4944")
            .renderingMode(.original)  // <----- this
            .resizable()
            .aspectRatio(contentMode: .fill)
            .frame(width: 370, height: 200)
            .clipped()
            .cornerRadius(20.0)
    

    【讨论】:

      【解决方案2】:

      这看起来像处理光栅图像的 SwiftUI 错误。请找到以下解决方法。使用 Xcode 11.4 / iOS 13.4 测试

      这是用于实现目标的单元格示例。当然在实际情况下,可以通过构造函数参数注入图片名称和导航链接目的地等。

      struct TestImageCell: View {
          @State private var isActive = false
      
          var body: some View {
              Image("large_image")    // raster !! image
                  .resizable()
                  .aspectRatio(contentMode: .fill)
                  .frame(width: 370, height: 200)
                  .cornerRadius(20.0)
                  .overlay(
                      Text("Press on me")              // text is over
                          .foregroundColor(.white)
                          .font(.largeTitle)
                  )
                  .onTapGesture { self.isActive.toggle() } // activate link on image tap
                  .background(NavigationLink(destination:  // link in background
                      Text("Detail view here"), isActive: $isActive) { EmptyView() })
          }
      }
      

      【讨论】:

        【解决方案3】:

        我用你的代码做了这个测试,一切正常,ios 13.4 和催化剂,xcode 11.4 和 macos catalina 10.15.4

        var body: some View {
            NavigationView {
                VStack {
                    Image(systemName: "person.2.fill")
                        .resizable()
                        .aspectRatio(contentMode: .fill)
                        .frame(width: 370, height: 200)
                        //.clipped()
                        .cornerRadius(20.0)
        
                    NavigationLink(destination: Text("Detail view here")){
                        ZStack{
                            Image(systemName: "person.2.fill")
                                .resizable()
                                .aspectRatio(contentMode: .fill)
                                .frame(width: 370, height: 200)
                                //.clipped()
                                .cornerRadius(20.0)
                            Text("Press on me")
                                .foregroundColor(.black)
                                .font(.largeTitle)
                        }
                    }
                }
            }.navigationViewStyle(StackNavigationViewStyle())
        }
        

        【讨论】:

        • 您输入了我的代码图像系统名称,但我需要输入代码图像,Mac OS Catalina 10.15.4、XCODE 版本 11.4 (11E146)、iOS 13,4 不起作用
        • 你是对的,我没有尝试其他图像类型,对不起。
        猜你喜欢
        • 1970-01-01
        • 2021-09-19
        • 2021-09-15
        • 2022-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-09
        相关资源
        最近更新 更多