跳到主要内容

useOrientation

跟踪用户设备的屏幕方向。

Usage

实时编辑器

function Demo() {
  const [state] = useOrientation();

  return <pre>{JSON.stringify(state, null, 2)}</pre>;
};

结果
Loading...

API

useOrientation

Returns

readonly [UseOrientationState, (type: UseOrientationLockType) => any, () => void]: 包含以下元素的元组:

  • 方向状态。
  • 锁定方向。
  • 解锁方向。

Arguments

参数名描述类型默认值
initialState初始值UseOrientationState | undefined-

UseOrientationState

参数名描述类型默认值
angle角度number (必填)-
type方向类型UseOrientationType | undefined (必填)-

UseOrientationType

Type

export type UseOrientationType = | "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary";

UseOrientationLockType

Type

export type UseOrientationLockType = | "any" | "natural" | "landscape" | "portrait" | "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary";