Home > Enterprise >  iOS: Pickers broken on iOS 16, working on 15
iOS: Pickers broken on iOS 16, working on 15

Time:12-13

I am working on creating a remote control app on iOS that involves pickers. On the iPhone SE, 3rd gen (iOS 15.6.1) I have been developing on, the pickers are coming out exactly as I intend. However, when I run the app on a simulator for a 3rd gen (16.1.1) iPhone SE, the pickers height is way off. Through testflight, I had a coworker download the app. He confirmed that, on his hardware, the pickers looked off. Here is what the picker is coming out like:

enter image description here

And here is how it looks on my iphone, how I intend it to look:

enter image description here

(My apologies for the different image sizes)

These pickers start as uninitialized class variables. When initializing the pickers, I want their height and width to be equal to the view they are seated in. When debugging this issue, I added two lines. One prints out the height argument I feed the constructor, and the other prints out the size of the picker after being constructed.

print("pickerRect height argument: "   String(Int(pickerFrame.frame.height))) // reading out 80
rolloffPicker = UIPickerView(frame: CGRect(x: 0, y: 0, width: pickerFrame.frame.width, height: pickerFrame.frame.height))
print("picker height: "   String(Int(rolloffPicker.frame.height))) // reading out 162

Now here is whats baffling me... On the physical iPhone SE it prints out 80 on both lines. For whatever reason, in the sim, it prints out the argument as 80, and the initialized size as 162. I have also tried constructing the CGRect before passing it in, the CGRect readsout 80 after being constructed, but once fed into the picker the size shoots up to 162 again. I have not touched the rolloffPicker variable until this line, and don't have any autolayout going with the picker.

My Mac is on Ventura 13.0.1, XCode is on Version 14.1. The physical iPhone was on 15.6.1, and the sim is on 16.1.1. When I updated the physical iPhone to 16.1.2, the pickers broke! Clearly this issue is in relation to the new update? What changed, and how might I work around it?

Update: Can't believe I missed this, but I am getting this message in the console when constructing the picker:

2022-12-09 19:35:14.434387-0700 Remote Control[645:22988] -[UIPickerView setFrame:]: invalid size {107, 72} pinned to {107, 162}

Update 2:

I tried to add constraints to the picker:

rolloffPicker.translatesAutoresizingMaskIntoConstraints = true
rolloffPicker.widthAnchor.constraint(equalToConstant: pickerFrame.frame.width).isActive = true
rolloffPicker.heightAnchor.constraint(equalToConstant: pickerFrame.frame.height).isActive = true

Now I am getting warnings, pickers size is way off...

CodePudding user response:

AHHHH I fixed it! I changed

rolloffPicker.translatesAutoresizingMaskIntoConstraints = true

to

rolloffPicker.translatesAutoresizingMaskIntoConstraints = false

while keeping the constraints. Why this broke between iOS 15 and 16 is an enigma to me, hopefully this can help someone else out in the future.

  • Related