WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

touchable area of pickerWheel overlapping / off screen

Forums > SwiftUI

When placing multiple pickers in an h stack, the touchable area overlaps. I haven't opened this app in quite awhile, and this was never a problem in my app before, but suddeny with ios 15 it is now non-functional. This must be a bug or something. When you run it in the simulator or deploy to a device, the touchable locations don't match up with the pickers. Has anyone else seen this? or have a solution i could try?

thank you so much

Brian

HStack {
                Picker(selection: $model.wholeNumberSelection, label: Text("Fraction")) {

                  ForEach(0 ..< model.wholeNumbers.count) {
                    Text(model.wholeNumbers[$0]).tag($0)
                  }
                }
                .frame(width: screen.width / 4, height: 160)
                .pickerStyle(WheelPickerStyle())
                .compositingGroup()
                .clipped()

                Picker(selection: $model.fractionsSelection, label: Text("Fraction")) {

                  ForEach(0 ..< model.fractions.count) {
                    Text(model.fractions[$0]).tag($0)
                  }

                }
                .frame(width: screen.width / 4, height: 160)
                .pickerStyle(WheelPickerStyle())
                .compositingGroup()
                .clipped()

                Picker(selection: $model.unitsSelection, label: Text("Units")) {
                    if(model.wholeNumberSelection <= 1) {
                  ForEach(0 ..< model.singularUnits.count) {
                    Text(model.singularUnits[$0]).tag($0)
                  }

                    } else {
                        ForEach(0 ..< model.pluralUnits.count) {
                          Text(model.pluralUnits[$0]).tag($0)
                        }
                    }
                }
                .frame(width: screen.width / 2, height: 160)
                .pickerStyle(WheelPickerStyle())
                .compositingGroup()
                .clipped()

            }

1      

You have already used the workaround that Apple had previously recommended to me for iOS15 beta, which is .compositingGroup().

Unfortunately after iOS15 beta was officially released as iOS15, the workaround appears to have become ineffective (possibly in 15.1, and definitely in 15.2).

Since I have an app on the AppStore, where I had used .compositingGroup, I had requested technical support. The technical support has been refunded by Apple, and asked that I send feedback to the iOS System Development team as this appears to be a more fundemental issue in SwiftUI. Currently awaiting further developments from Apple.

There maybe a solution in UIKit, but I have not investigated that further. Also I wish to keep developing in SwiftUI as much as possible.

1      

Thank you for replying, that is really unfortunate news. I feel your pain, as i too have an app in the store that needs to be updated for ios15, but i can't do so, as my app relys on side by side by side picker wheels for the UI. Hopefully this gets fixed, as I'm currently stuck and not sure what to do about my app.

1      

I just ran into the same problem with 2 pickers in an HStack--minutes and seconds. Even though they're in an HStack, I changed the zindex of the right most (overlapping) picker to be less than the left one which seems to work. More testing may be needed.

VStack {
    HStack {
        HStack {
            Picker("Minutes", selection: $minutes) {
                ForEach(0...59, id:\.self) {
                    Text("\($0)")
                }
            }
            .pickerStyle(WheelPickerStyle())
            .frame(maxWidth: pickerWidth, maxHeight: pickerHeight)
            .compositingGroup()
            .clipped(antialiased: true)
            .padding(.leading)

            Text("Minutes")
                .lineLimit(1)
                .minimumScaleFactor(0.1)
        }
        .padding(.leading)

        Spacer()

        HStack {
            Picker("Seconds", selection: $seconds) {
                ForEach(0...59, id:\.self) {
                    Text("\($0)")
                }
            }
            .pickerStyle(WheelPickerStyle())
            .frame(maxWidth: pickerWidth, maxHeight: pickerHeight)
            .compositingGroup()
            .clipped(antialiased: true)

            Text("Seconds")
                .lineLimit(1)
                .minimumScaleFactor(0.1)
                .padding(.trailing)
        }
        .padding(.trailing)
        .zIndex(-2)

    }
    .padding(.top, 35)
    Spacer()
}

   

I found this workaround. All credit to wyhgood.

Hopefully Apple will soon sort out a Swift solution to the compositingGroup() issue. I have tried the above, on iOS 15.4 simulator, adpating it to a single Int instead of an array Doubles as in their example, and with three elements in the HStack.

Edit: Another related workaround, based on the same principle of using a UIViewRepresentable struct. Credit to Steve M.

   

Hi guys, I have a workaround for iOS 15+.

Use .scaleEffect(x: 0.5) to half the touchable area, of the Inline picker.

This will however also squish the text inside it, to fix this, apply .scaleEffect(x: 2), ONLY to the text inside the ForEach.

Posted it on Stackoverflow: https://stackoverflow.com/a/72163536/16899401

Hope it helps :)

   

Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!

Read the book

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.