提问人:uncleX 提问时间:4/29/2023 更新时间:4/29/2023 访问量:176
SwiftUI 水平轮式选取器单元格项目大小
SwiftUI horizontal wheel picker cell item size
问:
我目前正在尝试实现水平选择器视图,用户可以在其中选择其头像衬衫。选取器的旋转和调整工作正常,但我选择的选取器视图单元格大小不会调整为我的项目数组的实际图像大小。这导致我的项目重叠。我已经尝试了很多,但是有没有办法解决这个问题,或者这是 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()
}
}
}
}
提前致谢
我尝试更改选择器的框架、layoutPriority、contentShape 等。
答: 暂无答案
评论
UIPickerView
UIViewRepresentable