Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

swift - Why am I getting “Position is ambiguous for MultiSelectSegmentedControl”?

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.

Simulator View

enter image description here

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...