tt.setDeviceOrientation
基础库 3.66.0 开始支持本方法,这是一个异步方法。
切换横竖屏,接口调用成功后会触发 tt.onDeviceOrientationChange 事件。
| 前提条件 | 从基础库版本 3.66.0 开始支持,使用该能力前请做好 canIUse 判断。 | 
| 业务背景 | 无 | 
| 使用限制 | 以下场景下无法使用该能力: 
 | 
| 注意事项 | 无 | 
| 相关教程 | 无 | 
语法
tt.setDeviceOrientation(options)
参数说明
options 为 object 类型,属性如下:
| 属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 | 
|---|---|---|---|---|---|
| value | enum | 是 | 表示切换为横屏还是竖屏,string 类型 | 3.66.0 | |
| success | function | 否 | 接口调用成功的回调函数 | 3.66.0 | |
| fail | function | 否 | 接口调用失败的回调函数 | 3.66.0 | |
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 3.66.0 | 
value 的合法值
| 值 | 说明 | 最低支持版本 | 
|---|---|---|
| landscape | 横屏 | 3.66.0 | 
| portrait | 竖屏 | 3.66.0 | 
回调成功
object 类型,属性如下:
| 属性名 | 类型 | 说明 | 最低支持版本 | 
|---|---|---|---|
| errMsg | string | setDeviceOrientation: ok | 3.66.0 | 
回调失败
object 类型,属性如下:
| 属性名 | 类型 | 说明 | 最低支持版本 | 
|---|---|---|---|
| errMsg | string | "setDeviceOrientation:fail" + 详细错误信息 | 3.66.0 | 
错误码
| errNo | errMsg | 说明 | 最低支持版本 | 
|---|---|---|---|
| 10401 | internal error | 小游戏框架内部错误,有需要请创建工单咨询 | 3.66.0 | 
| 21100 | setDeviceOrientation: can't set device orientation in live | 直播场景下禁止使用该API | 3.66.0 | 
| 21101 | setDeviceOrientation: can't set device orientation in x screen | x分屏场景下禁止使用该API | 3.66.0 | 
| 21102 | setDeviceOrientation: can't set device orientation in direct play | 直玩场景下禁止使用该API | 3.66.0 | 
| 21103 | setDeviceOrientation: can't set device orientation in current device model | 当前机型不支持该 API | 3.66.0 | 
扫码体验
请使用字节宿主APP扫码
代码示例
tt.setDeviceOrientation({ value: 'landscape', success() { console.log('转屏成功') }, fail() { console.log('转屏失败') }, });
