Picker overlapping each other

I got my xcode to update this morning. It prompted me to update and so I did. Since then, I have issues with Pickers on my app. I have two Pickers next to each other horizontally. However the dragGesture on each is off, by large!

HStack(alignment: .center, spacing: 0) {
      Spacer()
      HStack(spacing: 8) {
        Picker("selectionHours", selection: $hour) {
          ForEach(selectionHours, id: \.self) {
            Text($0)
              .font(.custom("Nunito-SemiBold", size: 28, relativeTo: .body))
          }
        }
        .labelsHidden()
        .frame(maxWidth: 60, maxHeight: 40)
        .clipShape(RoundedRectangle(cornerRadius: 15.0))
        .clipped()
         
        Text("hours_short")
          .font(.custom("Nunito-SemiBold", size: 22, relativeTo: .body))
      }
      .foregroundColor(Color.primary)
       
      Spacer()
       
      HStack(spacing: 8) {
        Picker("selectionMinutes", selection: $minute) {
          ForEach(selectionminutes, id: \.self) { index in
            Text(index)
              .font(.custom("Nunito-SemiBold", size: 28, relativeTo: .body))
          }
        }
        .labelsHidden()
        .frame(maxWidth: 60, maxHeight: 40)
        .clipShape(RoundedRectangle(cornerRadius: 15.0))
        .clipped()
         
        Text("minutes_short")
          .font(.custom("Nunito-SemiBold", size: 22, relativeTo: .body))
          .foregroundColor(Color.primary)
      }
      .foregroundColor(Color.primary)
     
      Spacer()
    }
    .frame(height: 70)

While trying to drag on the left picker, it scrolls on the right one. If I remove: .clipped you can see the "scrollable" area that is overlapping. This issue started as I mentioned this morning with an update, now the simulator is running ios 15. It feels like a ios 15 bug. I have no access to a physical ios device and cannot test it at the moment on a physical device to see if it's a simulator/xcode bug or swiftui bug.

Accepted Reply

There was a similar issue (with wheel picker) reported on the forum a few days ago.

Could you have a look at it and see if it gives clues to solve your problem ?

https://developer.apple.com/forums/thread/690610

But you have many things to display in horizontal stack. Try to rotate the device to see if the problem still there.

  • Thank you, your link provided correct solution. .compositingGroup() was needed on both pickers :) Thank you, again!

  • .compositingGroup() is not helping on iOS 15.1, it worked on iOS 15

Add a Comment

Replies

Trying your code on an iPad, where there is plenty of room (and using WheelPickerStyle(), so it looks the same as the phone version), it works okay.
Which suggests that you may be running out of space.
I would look at the framing and clipping code, perhaps get rid of that, and start from clean, then gradually add it back?

  • I'm not sure that is correct. This specific code used to work just 24 hours ago. Also, as you can see on the on the code, there is a frame of maxWidth of 60 on each. That used to be about 35% of the screen. I confirmed this by placing borders on the pickers. Finally, I forgot to mention I did add Pickerstlye(.wheel) but I forgot to include it in here. Speaking of frames, I also tried using GeometryReader and then screenwidth/2 (even divide by 3 or 4) and did not work. The clipping I feel is necessary, is it not?

Add a Comment

There was a similar issue (with wheel picker) reported on the forum a few days ago.

Could you have a look at it and see if it gives clues to solve your problem ?

https://developer.apple.com/forums/thread/690610

But you have many things to display in horizontal stack. Try to rotate the device to see if the problem still there.

  • Thank you, your link provided correct solution. .compositingGroup() was needed on both pickers :) Thank you, again!

  • .compositingGroup() is not helping on iOS 15.1, it worked on iOS 15

Add a Comment