且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式锁定/解锁iphone的方向锁?

更新时间:2022-06-11 03:01:40

您是否在询问是否可以为您的应用执行此操作或锁定设备本身的方向?在我看来,你问的是后者,我不得不问你为什么要那样做。无法锁定设备的方向,因为它也可以在纵向模式下锁定其他应用程序。

Are you asking if you can do this for your app or lock the orientation for the device itself? Seems to me you're asking for the latter and I would have to ask why you want to do that. It's not possible to lock the orientation for the device, because that way it would be locked in portrait mode for other apps as well.

但是,您只能支持您的方向想要自己。许多应用程序仅支持纵向模式,游戏通常仅支持横向。

You can however only support the orientations you want yourself. A lot of apps only support portrait mode and games generally support landscape only.

您可以在XCode中设置应用程序支持的设备方向。在viewcontroller。

You can set the supported device orientations of your app in XCode. At the viewcontroller.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

假设你想支持两种横向方向。

Assuming you want to support both landscape orientations.