This is a synopsis of the LiveCode language elements that you can use to handle various screen sizes and device orientations in mobile devices. For more information see the iOS and Android release notes in LiveCode (available from the Help menu) and the LiveCode Dictionary.
the screenRect function – the rectangular area(s) of the screen(s); e.g. 0,0,2560,1440
the working screenRect variant – same as the screenRect, minus the area covered by screen furniture like the task bar on Windows and the menubar and dock on Mac OS. On mobile devices the status bar is excluded from the working screenRect; e.g. 0,22,2560,1390
set the rect of this stack to the working screenRectthe effective working screenRect variant – adding the effective modifier returns the area of the screen the application has to itself. On mobile devices if the keyboard is visible, it will take into account the space the keyboard is taking up on the screen; e.g. 0,22,2560,800
set the rect of this stack to the effective working screenRectthe screenLoc function – returns an x,y coordinate describing the exact center of the screen, in distance from the left and distance from the top of the screen; e.g., 1280,720
set the loc of this stack to the screenLocresizeStack message – Handle this message to resize and reposition objects on the card whenever the orientation of the device changes. See the screen geometry reading for more details on using
resizeStack
.
messages
orientationChanged – This message is sent when the device detects a change in its orientation relative to the ground, but before the interface is updated. That means you can intercept the orientation change and lock the rotation before the interface updates. Note that normally you would use the resizeStack message to use to resize and reposition your objects.
commands
mobileSetAllowedOrientations – Use this command early in the startup sequence to allow your app to respond to orientation changes. Your window will automatically orient itself to the new orientation. You should then use a
resizeStack
message handler to resize and reposition objects to appropriate sizes and positions for the new orientation.mobileSetAllowedOrientations "portrait,portrait upside down,landscape left,landscape right"mobileLockOrientation – Use this command to temporarily prevent orientation changes.
mobileUnlockOrientation – Use this command to allow orientation changes which had been temporarily prevented.
functions
mobileDeviceOrientation() – Tells you the current orientaion of the mobile device.
mobileOrientation() – Tells you the current orientaion of your interface.
mobileAllowedOrientations() – Tells you which orientations have been set by the
mobileSetAllowedOrientations
command.mobileOrientationLocked() – Tells you whether the orientation has been locked by the
mobileLockOrientation
command.