【问题标题】:SwiftUI Context Menu with image like Photos app带有图像的 SwiftUI 上下文菜单,例如照片应用程序
【发布时间】:2021-09-14 08:30:15
【问题描述】:

我想以与 Apple 照片应用程序相同的方式使用上下文菜单:当您长时间按下方形图像时,您会以图像的原始格式获得图像的全屏预览,并且不像网格中的正方形。但是当我使用上下文菜单时,预览的格式与显示的格式相同。

这是我的代码,在此先感谢。

struct CardView: View {
    let url: URL
    var body: some View {
        GeometryReader { proxy in
            AnimatedImage(url: url)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: proxy.size.width, height: proxy.size.height, alignment: .center)
                .cornerRadius(4)
                .contextMenu(ContextMenu(menuItems: {
                    Button {
                        print("Saved \(url)")
                    } label: {
                        HStack {
                            Text("Save Image")
                                .padding(20)
                            Image(systemName: "square.and.arrow.down")
                                .resizable()
                                .font(.title)
                        }
                    }
                }))
        }
    }
}

【问题讨论】:

    标签: swiftui contextmenu


    【解决方案1】:

    我发现使用 SwiftUI 3,在 WWDC 2021 期间,他们提出了一种实现这一目标的方法。您可以在此视频中看到以下内容。

    https://www.youtube.com/watch?v=4eRXNtjA0ng

    【讨论】:

      猜你喜欢
      • 2021-12-16
      • 1970-01-01
      • 2023-02-09
      • 1970-01-01
      • 1970-01-01
      • 2021-05-24
      • 1970-01-01
      • 2022-11-18
      • 1970-01-01
      相关资源
      最近更新 更多