Swift 为什么我会得到“;多选分段控件的位置不明确”;?
我喜欢此软件包提供的外观和功能: 通过一个赤裸裸的项目,我获得了正确的功能,但由于模糊的约束,有几个屏幕充满了警告 无法同时满足约束 我将3个主文件复制到本地项目中,并添加了一行禁用Swift 为什么我会得到“;多选分段控件的位置不明确”;?,swift,swiftui,autolayout,Swift,Swiftui,Autolayout,我喜欢此软件包提供的外观和功能: 通过一个赤裸裸的项目,我获得了正确的功能,但由于模糊的约束,有几个屏幕充满了警告 无法同时满足约束 我将3个主文件复制到本地项目中,并添加了一行禁用translatesAutoresizingMaskIntoConstraints 到MultiSegmentPicker.swift中init的开头: _selectedSegmentIndexes = selectedSegmentIndexes uiView = MultiSelectSegme
translatesAutoresizingMaskIntoConstraints
到MultiSegmentPicker.swift中init的开头:
_selectedSegmentIndexes = selectedSegmentIndexes
uiView = MultiSelectSegmentedControl(items: items)
uiView.translatesAutoresizingMaskIntoConstraints = false // <<== added here
我已经检查了约束是如何应用于视图/控件的,没有发现任何歧义。我猜这是UIViewRepresentable接口中的一个bug。我不知道如何进一步调试这个。有人能提供一些指导吗?我尝试创建UIViewControllerRepresentable对象,但没有成功
一旦您更改了ui视图.translatesAutoResizengMaskintoConstraints
后,这就是重现问题所需的一切:
//import MultiSelectSegmentedControl
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
.padding()
DummyControl()
.fixedSize()
}
}
}
struct DummyControl: View {
@State var selectedSegmentIndexes = IndexSet()
let items = ["a", "b", "c"]
var body: some View {
MultiSegmentPicker(selectedSegmentIndexes: $selectedSegmentIndexes, items: items)
.fixedSize()
.padding()
}
}
//import MultiSelectSegmentedControl
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
.padding()
DummyControl()
.fixedSize()
}
}
}
struct DummyControl: View {
@State var selectedSegmentIndexes = IndexSet()
let items = ["a", "b", "c"]
var body: some View {
MultiSegmentPicker(selectedSegmentIndexes: $selectedSegmentIndexes, items: items)
.fixedSize()
.padding()
}
}