English 中文(简体)
背景菜单对随机地点的反应
原标题:Context menu responds to random locations

The snippet of the Code which establish this list:

ScrollView {
    LazyVGrid(columns: columns, alignment: .leading, spacing: 8) {
        ForEach(viewModel.previews) { item in
            PreviewCard(item: item)
                .contextMenu(
                    ContextMenu(menuItems: {
                        Text("Menu Item 1 (item.size)")
                    }))
                .cornerRadius(7)
                .shadow(radius: 3)
                .padding(3)
        }
    }
}
struct PreviewCard: View {
    private let item: PreviewPayload
    
    init(item: PreviewPayload) {
        self.item = item
    }
    
    var body: some View {
        ZStack(alignment: .bottomLeading) {
            AsyncImage(url: item.preview) { image in
                image
                    .resizable()
                    .scaledToFill()
                
            } placeholder: {
                ProgressView()
            }
            .frame(width: 100, height: 200)
            
            VStack(alignment: .leading, spacing: 4) {
                Text(TextFormatter.formatSize(item.size))
                
                if let date = TextFormatter.formatDate(item.createdDate) {
                    Text(date)
                }
            }
            .padding()
        }
    }
}

这里指的是:

enter image description here

对错误项目的审查正在进行。 我很想知道,它是否与LazyVGrid有任何关系,或者我是否失踪?

问题回答

很显然,问题在于可点击的领域,添加了<代码>。contentShape(Rectangle()),作为最后修订案文。





相关问题
SwiftUI: How do I position a button x points above a sheet?

I am trying to recreate a Maps-style UI with a persistent bottom sheet and controls fixed above. Apple Maps UI with controls above ☝️ Example here, the "Look Around" binoculars button and ...

How to access own window within SwiftUI view?

The goal is to have easy access to hosting window at any level of SwiftUI view hierarchy. The purpose might be different - close the window, resign first responder, replace root view or ...

热门标签