I like the looks and functionality provided by this package:
https://github.com/yonat/MultiSelectSegmentedControl
With a barebones project I get correct functionality, but a couple of screens full of warnings because of ambiguous constraints.
Unable to simultaneously satisfy constraints.
I copied the 3 main files to the local project and added one line disabling translatesAutoresizingMaskIntoConstraints
to the beginning of the init in MultiSegmentPicker.swift:
_selectedSegmentIndexes = selectedSegmentIndexes
uiView = MultiSelectSegmentedControl(items: items)
uiView.translatesAutoresizingMaskIntoConstraints = false // <<== added here
Once I did this, everything works perfectly. Unless I try to debug the view.
I get a purple triangle with an "!" and the message:
“Position is ambiguous for MultiSelectSegmentedControl”
I have reviewed how the constraints are applied to the views/control and haven't found any ambiguity. So my guess is that this is a bug in the UIViewRepresentable interface. I don't know how to debug this further. Can anyone provide some guidance? I tried creating a UIViewControllerRepresentable object, but did not have success.
Once you make the uiView.translatesAutoresizingMaskIntoConstraints
change, this is everything you need to reproduce the problem:
//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()
}
}
question from:
https://stackoverflow.com/questions/65601802/why-am-i-getting-position-is-ambiguous-for-multiselectsegmentedcontrol 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…