Skip to content

orientation ​

go
import "github.com/tangoui/tango/sys/orientation"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package orientation reads and locks the interface orientation.

o, _ := orientation.Get(a)            // orientation.Portrait, ...
orientation.Lock(a, orientation.Landscape)
orientation.Unlock(a)
orientation.OnChange(a, func(o orientation.Orientation) { ... })

Locking only chooses among the orientations the app declares (UISupportedInterfaceOrientations on iOS; Android allows all). On iPad, apps that support multitasking (split view) cannot lock; iOS ignores the request there.

Functions return ErrUnsupported on desktop and tango.ErrNotRunning after the app quit.

常量 ​

go
const (
	Unknown            = platform.OrientationUnknown
	Portrait           = platform.OrientationPortrait
	PortraitUpsideDown = platform.OrientationPortraitUpsideDown
	LandscapeLeft      = platform.OrientationLandscapeLeft
	LandscapeRight     = platform.OrientationLandscapeRight
)
go
const (
	MaskPortrait           = platform.MaskPortrait
	MaskPortraitUpsideDown = platform.MaskPortraitUpsideDown
	MaskLandscapeLeft      = platform.MaskLandscapeLeft
	MaskLandscapeRight     = platform.MaskLandscapeRight
	Landscape              = platform.MaskLandscape // either landscape
	PortraitOnly           = platform.MaskPortrait
	All                    = platform.MaskAll
)

变量 ​

go
var ErrUnsupported = platform.ErrUnsupported

函数 ​

func IsLandscape ​

go
func IsLandscape(o Orientation) bool

IsLandscape reports whether o is a landscape orientation.

func Lock ​

go
func Lock(a *tango.App, m Mask) error

Lock restricts the interface to m, rotating if needed.

func OnChange ​

go
func OnChange(a *tango.App, fn func(Orientation))

OnChange calls fn on the main thread with the new orientation whenever it changes. It does nothing on desktop.

func String ​

go
func String(o Orientation) string

String names o: "portrait", "portraitUpsideDown", "landscapeLeft", "landscapeRight" or "unknown".

func Unlock ​

go
func Unlock(a *tango.App) error

Unlock lifts a Lock.

类型 ​

Mask ​

go
type Mask = platform.OrientationMask

Mask is a set of orientations for Lock.

Orientation ​

go
type Orientation = platform.Orientation

Orientation is named by where the device's top edge points: LandscapeLeft is the device turned 90° counter-clockwise from portrait.

func Get ​

go
func Get(a *tango.App) (Orientation, error)

Get returns the current interface orientation.

以 MIT 许可发布