Use this API to lock the screen to a specific orientation. This is useful for video players, games, or other content that requires a specific orientation.
Parameters
Property Type Required Description orientation String Yes Target orientation: auto, portrait, landscape success Function No Callback on success fail Function No Callback on failure complete Function No Callback that always executes
Code Example
Basic Usage
my . setScreenOrientation ({
orientation: 'landscape' ,
success () {
console . log ( 'Orientation set to landscape' );
}
});
Video Player Full Screen
Page ({
enterFullscreen () {
my . setScreenOrientation ({
orientation: 'landscape' ,
success : () => {
this . setData ({ isFullscreen: true });
}
});
},
exitFullscreen () {
my . setScreenOrientation ({
orientation: 'portrait' ,
success : () => {
this . setData ({ isFullscreen: false });
}
});
},
onUnload () {
// Ensure orientation is reset
my . setScreenOrientation ({ orientation: 'auto' });
}
});
Game Orientation Lock
Page ({
onLoad () {
// Lock to landscape for game
my . setScreenOrientation ({
orientation: 'landscape'
});
},
onUnload () {
// Allow auto rotation when leaving
my . setScreenOrientation ({
orientation: 'auto'
});
}
});
Orientation Options
Value Description autoAllow automatic rotation based on device orientation portraitLock to portrait (vertical) mode landscapeLock to landscape (horizontal) mode
Always reset orientation to auto when leaving a page that locked the orientation, otherwise users may be stuck in an unexpected orientation.
my.getScreenOrientation Get current orientation
my.onScreenOrientationChange Listen for changes