Parameters
Success Callback Parameters
Code Example
Basic Usage
Video Player Full Screen
Game Orientation Lock
Orientation Options
Related APIs
my.getScreenOrientation
Get current orientation
my.onScreenOrientationChange
Listen for changes
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Set the screen orientation.
| Property | Type | Required | Description |
|---|---|---|---|
| orientation | String | Yes | Indicates the orientation of the screen, portrait or landscape. |
| success | Function | No | Callback on success |
| fail | Function | No | Callback on failure |
| complete | Function | No | Callback that always executes |
| Property | Type | Description |
|---|---|---|
| success | Boolean | Specifies whether the call is successful. When the value is true, the call is successful. |
my.setScreenOrientation({
orientation: 'landscape',
success() {
console.log('Orientation set to landscape');
}
});
Page({
enterFullscreen() {
my.setScreenOrientation({
orientation: 'landscape',
success: () => {
this.setData({ isFullscreen: true });
}
});
},
exitFullscreen() {
my.setScreenOrientation({
orientation: 'portrait',
success: () => {
this.setData({ isFullscreen: false });
}
});
},
onUnload() {
// Restore portrait when leaving the page
my.setScreenOrientation({ orientation: 'portrait' });
}
});
Page({
onLoad() {
// Lock to landscape for game
my.setScreenOrientation({
orientation: 'landscape'
});
},
onUnload() {
// Restore portrait when leaving
my.setScreenOrientation({
orientation: 'portrait'
});
}
});
| Value | Description |
|---|---|
portrait | Lock to portrait (vertical) mode |
landscape | Lock to landscape (horizontal) mode |
portrait when leaving a page that locked the orientation, otherwise users may be stuck in an unexpected orientation.