SwiftUI 水平轮式选取器单元格项目大小

SwiftUI horizontal wheel picker cell item size

提问人:uncleX 提问时间:4/29/2023 更新时间:4/29/2023 访问量:176

问:

我目前正在尝试实现水平选择器视图,用户可以在其中选择其头像衬衫。选取器的旋转和调整工作正常,但我选择的选取器视图单元格大小不会调整为我的项目数组的实际图像大小。这导致我的项目重叠。我已经尝试了很多,但是有没有办法解决这个问题,或者这是 iOS 16.4 中的常见问题?

    @ViewBuilder func customAvatarView() -> some View {
        List {
            ForEach(Array(sections.enumerated()), id: \.offset) { sectionIndex, element in
                VStack(spacing: 0) {
                    Picker("\(element)", selection: $currentSelection[sectionIndex], content: {
                        DynamicFetchView(predicate: NSPredicate(format: "userID == %@", Auth.auth().currentUser!.uid), sortDescriptors: []) { (shopItems: FetchedResults<ShopData>) in
                            ForEach(shopItems.filter { $0.category == element }, id: \.self) { shopItem in
                                if let image = UIImage(named: shopItem.image ?? "") {
                                    HStack {
                                        Image(uiImage: image)
                                            .resizable()
                                            .frame(width: 150, height: 150)
                                            .rotationEffect(Angle(degrees: 90))
                                    }
                                }
                            }
                        }
                    })
                    .pickerStyle(.wheel)
                    .rotationEffect(Angle(degrees: -90))
                    .clipped()
                    .compositingGroup()
                }
            }
        }
    }

enter image description here

提前致谢

我尝试更改选择器的框架、layoutPriority、contentShape 等。

iOS SwiftUI swiftUI 选择器

评论

0赞 alexkaessner 6/28/2023
对于SwiftUI本身来说,这似乎是不可能的。查看这篇文章,了解桥接到使用的解决方案:stackoverflow.com/questions/61625848/...UIPickerViewUIViewRepresentable
0赞 alexkaessner 6/28/2023
这回答了你的问题吗?SwiftUI:设置选取器行高

答: 暂无答案