Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autolayout issue with zoomed display with iPhone6 and 6Plus

I am using Auto Layout and Size Classes in my storyboard and have a button that has a vertical constraint to the bottom of my view controller. However, when I run my app on my iPhone6 Plus in zoomed mode (Settings -> Display & Brightness -> Display Zoom -> Zoomed) the button doesn't reposition itself.

Is this a bug? If so, what would be the best workaround, I could find out if the app is in zoomed mode and change the constraint accordingly?

Or am I doing something else wrong here?

like image 784
m.y Avatar asked Feb 08 '23 03:02

m.y


2 Answers

Basically, an iPhone 6+ in zoom mode is an iPhone 6. And an iPhone 6 in zoom mode is an iPhone 5. You shouldn't have to change anything, just make sure that your code works on iPhone 5 and 6.

And don't try finding out which phone you are running on. For example, there are ways by using some device info to find that you are running on a certain iPhone model - if you use these methods then your code might think it's running on an iPhone 6+ when it is zoomed and get everything wrong. Just check the size of the screen (and make sure that you check for rotation as well).

like image 95
gnasher729 Avatar answered Feb 10 '23 23:02

gnasher729


The solution I found was to add constraints to my container view. There was code that was setting the container view frame programatically based on a background image.

No matter if in zoomed or standard display mode, the actual background image's size doesn't change even though it will all fit on the screen as it gets scaled. So my container frame ended up bigger than expected and hence why my button was almost out of the device's screen.

like image 26
m.y Avatar answered Feb 10 '23 22:02

m.y