抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • API 概览
  • C# API
  • 开放接口
  • 收藏
  • 群聊
  • 关注
  • 数据分析
  • 基础
  • 渲染
  • 设备
  • 加速计
  • 剪贴板
  • 罗盘
  • 网络
  • 屏幕
  • 振动
  • 扫码
  • 陀螺仪
  • 设备方向
  • 日历
  • 滚轮
  • 键盘
  • 鼠标
  • 转屏
  • tt.setDeviceOrientation
  • tt.onDeviceOrientationChange
  • tt.offDeviceOrientationChange
  • 文件
  • 位置
  • 媒体
  • 网络
  • 转发
  • 数据缓存
  • 广告
  • 界面
  • 支付
  • Worker
  • tt.setDeviceOrientation

    收藏
    我的收藏

    基础库 3.66.0 开始支持本方法,这是一个异步方法。

    切换横竖屏,接口调用成功后会触发 tt.onDeviceOrientationChange 事件。

    前提条件

    从基础库版本 3.66.0 开始支持,使用该能力前请做好 canIUse 判断。

    业务背景
    使用限制

    以下场景下无法使用该能力:

    • 直播场景
    • x 分屏场景
    • 直玩场景
    • pad 场景
    • 折叠屏场景
    注意事项
    相关教程

    语法

    tt.setDeviceOrientation(options)

    参数说明

    options 为 object 类型,属性如下:

    属性名类型默认值必填说明最低支持版本
    valueenum

    表示切换为横屏还是竖屏,string 类型

    3.66.0
    successfunction
    接口调用成功的回调函数
    3.66.0
    failfunction
    接口调用失败的回调函数
    3.66.0
    completefunction
    接口调用结束的回调函数(调用成功、失败都会执行)
    3.66.0

    value 的合法值

    说明最低支持版本
    landscape

    横屏

    3.66.0
    portrait

    竖屏

    3.66.0

    回调成功

    object 类型,属性如下:

    属性名类型说明最低支持版本
    errMsgstring

    setDeviceOrientation: ok

    3.66.0

    回调失败

    object 类型,属性如下:

    属性名类型说明最低支持版本
    errMsgstring

    "setDeviceOrientation:fail" + 详细错误信息

    3.66.0

    错误码

    errNoerrMsg说明最低支持版本
    10401internal error
    小游戏框架内部错误,有需要请创建工单咨询
    3.66.0
    21100setDeviceOrientation: can't set device orientation in live

    直播场景下禁止使用该API

    3.66.0
    21101setDeviceOrientation: can't set device orientation in x screen

    x分屏场景下禁止使用该API

    3.66.0
    21102setDeviceOrientation: can't set device orientation in direct play

    直玩场景下禁止使用该API

    3.66.0
    21103setDeviceOrientation: can't set device orientation in current device model

    当前机型不支持该 API

    3.66.0

    扫码体验

    请使用字节宿主APP扫码

    代码示例

    开发者工具中预览

    tt.setDeviceOrientation({ value: 'landscape', success() { console.log('转屏成功') }, fail() { console.log('转屏失败') }, });