Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS应用程序方向旋转根据应用程序的配置锁定/解锁_Ios_Rotation_Orientation - Fatal编程技术网

iOS应用程序方向旋转根据应用程序的配置锁定/解锁

iOS应用程序方向旋转根据应用程序的配置锁定/解锁,ios,rotation,orientation,Ios,Rotation,Orientation,嗨 我正在尝试对我的iOS应用程序实现方向旋转锁定/解锁切换开关 锁定是可以的,但解锁是一个问题 假设应用程序的方向和设备的方向不同。如果用户在这种情况下解锁,应用程序的方向应该立即跟随设备的方向。但是我找不到路 如何模拟设备的方向旋转 编辑 我会澄清情况的 应用程序中有一个切换开关,启用/禁用方向旋转 逐步: 一,。开关已启用 二,。设备旋转到portlait 三,。UIViewController的shouldAutorotateToInterfaceOrientation为每个方向返回YE

我正在尝试对我的iOS应用程序实现方向旋转锁定/解锁切换开关

锁定是可以的,但解锁是一个问题

假设应用程序的方向和设备的方向不同。如果用户在这种情况下解锁,应用程序的方向应该立即跟随设备的方向。但是我找不到路

如何模拟设备的方向旋转

编辑

我会澄清情况的

应用程序中有一个切换开关,启用/禁用方向旋转

逐步:

一,。开关已启用

二,。设备旋转到portlait

三,。UIViewController的shouldAutorotateToInterfaceOrientation为每个方向返回YES

四,。应用程序旋转到portlait

五,。用户将开关切换为禁用

六,。设备旋转到横向

七,。UIViewController的shouldAutorotateToInterfaceOrientation返回除portlait之外的任何值

八,。应用程序不旋转

九,。用户切换开关以启用


十,。应用程序应旋转到横向。这就是问题所在。

我还没有尝试过,但是有一个viewController方法尝试旋转到DeviceOrientation iOS5。也许值得一试。有趣的问题。报告是否有效

// call this method when your return value from shouldAutorotateToInterfaceOrientation: changes
// if the current interface orientation does not match the current device orientation, 
// a rotation may occur provided all relevant view controllers now return YES from shouldAutorotateToInterfaceOrientation:
+ (void)attemptRotationToDeviceOrientation __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);

您可以阅读技术问答QA1688,其中涉及自动反应,并在每个viewcontroller中显示消息shouldAutorotateToInterfaceOrientation:根据您的开关设置返回正确的值。您的info.plist中还有一个开关。标记确保您在此处也有正确的设置

在此处查看我的答案:

我制作了一个定制的UINavigationController,在那里您可以检查您在哪个视图中,并使用正确的掩码进行响应。我希望根视图是纵向的

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    if([self.viewControllers count] == 1) return UIInterfaceOrientationMaskPortrait;
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}

等等,你如何锁定设备的方向?通过实现shouldAutorotateToInterfaceOrientation。它进行旋转。但这种方式有一个问题。当调用UIViewController的didRotateFromInterfaceOrientation时,图幅大小仍然是不变的值。如果设备旋转,则该值为新值。您是否正在根据用户优先级和当前方向更改shouldAutorotateToInterfaceOrientation返回的内容?可能需要更多的摆弄才能让它发挥作用-不要放弃-