Detecting iOS Home Bar location

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SteveB
Posts: 40
Joined: Mon Sep 30, 2019 4:49 pm

Detecting iOS Home Bar location

Post by SteveB » Thu Mar 18, 2021 2:21 pm

Is there any way to detect the location of the Home Bar that appears on later iOS devices that don't have a button? I'm building an app with buttons at the bottom of the screen, and want to position these just above the Home Bar if it is being run one of those devices without the home button.

Effective screenRects doesn't work, as it doesn't seem to take the Home Bar into account. I can work around by setting my buttons 10% up from the bottom of the screen, but there must be a better way. Any ideas?

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 257
Joined: Sat Aug 16, 2008 9:48 am
Location: Stockholm, Sweden
Contact:

Re: Detecting iOS Home Bar location

Post by SWEdeAndy » Fri Mar 26, 2021 6:56 pm

Unfortunately, there is no easy way, as far as I know. Your app will have to find out which device it's on, by comparing the screen size to a lookup table that you need to provide (either hardcode into the app or have the app fetch on the fly).

Useful resources for iOS screen resolutions:
https://ios-resolution.com/
https://www.paintcodeapp.com/news/ultim ... esolutions (nicer presentation, but doesn't have the latest models)

Basically, if the device has the "notch" at the top it also has no physical button at the bottom, so it will need extra margins both ways. Minimum is normally 44 px at the top and 34 px at the bottom.

I did some scripts for it two years ago that I could find and post. They can probably be improved on.

Here's also a very interesting design guide that I've recently found:
https://learnui.design/blog/ios-design- ... lates.html
Andreas Bergendal
Independent app and system developer
WhenInSpace: https://wheninspace.se

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Detecting iOS Home Bar location

Post by bwmilby » Fri Mar 26, 2021 11:01 pm

Check out:
https://github.com/Himalayan-Academy/Si ... codescript
Lines 36-223

Key handlers are "_setPhoneModel" and "safe...Margin". You use "setCardCoords" to initialize.

The reason for some of the orientation code is due to the project there are times where the orientation needs to be forced because when the preOpenXXX handler fires the engine hasn't caught up with the display orientation (especially a problem when going from one stack to another with an orientation switch). If your stack is just portrait, then you can eliminate a bit of the code there.

Since this is an active project, as Apple adds devices that require additional code it will get updated.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

SteveB
Posts: 40
Joined: Mon Sep 30, 2019 4:49 pm

Re: Detecting iOS Home Bar location

Post by SteveB » Sat Mar 27, 2021 12:53 pm

Thanks SWEdeAndy and bwmilby for your replies.

Yes, I knew how to detect the iPhone model from this post:

viewtopic.php?f=49&t=30679

I did my own tests by building an app with a crosshair cursor and having it report screen dimensions and cursor position as I dragged it around. Running it in all the devices in Simultor showed me that there is a difference (albeit small) between devices.

My app is landscape only and doesn't use a Tab Bar (uses sideways swipe instead), so I am interested in how far up from the bottom (or side in landscape) the Home Bar is.

Generally speaking, the Home Bar centre line is 2.5% up from the bottom edge, so putting the bottom of a button 5% up puts the Home Bar roughly midway between the bottom of the button and the screen edge, but it does vary a little from device to device, but 5% is an acceptable compromise for current devices.

Given that it does vary a little from device to device, my concern is what happens when the next iPhone is released. I don't want to have to keep going back and rebuilding apps for the App Store if Apple redesign the screen layout, but this may be the only way since [[effective] working] screenRect only ever returns the screen dimensions in iOS.

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Detecting iOS Home Bar location

Post by bwmilby » Sat Mar 27, 2021 2:24 pm

About the only thing you could do is to use the screen ratio instead of actual pixel size to determine if it is going to have that virtual button. My guess is that Apple is going to eventually remove the physical button from all phones but in doing so the aspect ratio will likely remain taller/wider for ones without the physical button even if it does change slightly.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

Post Reply

Return to “iOS Deployment”