由于ShouldAutorotateToInterfaceOrientation在iOS 6中已弃用并且我使用它来强制特定视图仅限于纵向,在iOS 6中执行此操作的正确方法是什么?这仅适用于我的应用的一个区域,所有其他视图都可以旋转.
我正在使用MGSplitViewController,我shouldAutorotateToInterfaceOrientation用来控制旋转时主视图控制器的大小.
它在iOS 5上运行良好,但在iOS 6(模拟器和iPad)shouldAutorotateToInterfaceOrientation上从未调用过.
这是一个我应该期望在iOS 6的最终版本中修复的错误或者我不知道已经改变的东西吗?
请注意以下答案 - 不适用于iOS6,所以我仍然需要一个答案!
我的应用程序仅在纵向模式下启用.
但是,如果我将UIImagePickerController作为子视图嵌入并旋转设备,则顶部和底部栏位于同一位置,但UIImagePickerController会旋转.
如何防止它旋转?
这是代码:
[self.view.window addSubview:self.imagePickerController.view];
self.imagePickerController.showsCameraControls = NO;
self.imagePickerController.view.frame = CGRectMake(0, 90, 320, 320);
self.imagePickerController.allowsEditing = NO;
Run Code Online (Sandbox Code Playgroud)
EDITED
我正在使用iOS6,其中shouldAutorotate不会被调用
我不希望我的应用程序被美化,并始终是porttrait.So我使我的应用程序部署信息只设置肖像.但是当我需要在我的应用程序中显示任何图像或视频时,我需要横向模式以便更好地显示.
我可以通过检测设备方向的变化
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
/* */
break;
case UIDeviceOrientationPortraitUpsideDown:
/* */
break;
case UIDeviceOrientationLandscapeLeft:
/* */
break;
case UIDeviceOrientationLandscapeRight:
/* */
break;
default:
break;
};
}
Run Code Online (Sandbox Code Playgroud)
但是,即使应用程序部署信息纵向被锁定,如何手动更改设备方向?
这不起作用
NSNumber *value=[NSNumber numberWithInt: UIDeviceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
Run Code Online (Sandbox Code Playgroud) ios ×4
ios6 ×2
iphone ×2
cocoa-touch ×1
objective-c ×1
orientation ×1
portrait ×1
xamarin.ios ×1
xcode ×1