orientation

Type Event
Revision Release 2024.3703
Keywords orientation
See also system.orientation
resize

Overview

Orientation events occur when the device orientation changes. This means that the orientation event will be triggered even for orientations that the app does not support, with a caveat for Android (see below).

Apps with a fixed orientation, for example "portrait" only, may use the orientation event to rotate the UI manually. However, for apps with multiple supported orientations, the orientation event should not be used to re-layout the UI — instead, the resize event should be used.

This event is also helpful if you’re using accelerometer or gyroscope data. This data is relative to portrait orientation, so you can use orientation events to handle the data based on the device’s current orientation.

Gotchas

Properties

event.type

event.name

event.delta

Example

local function onOrientationChange( event )
    local currentOrientation = event.type
    print( "Current orientation: " .. currentOrientation )
end
 
Runtime:addEventListener( "orientation", onOrientationChange )