我不希望我的应用程序被美化并且始终是纵向的。所以我将我的应用程序部署信息设置为仅设置纵向。但是当我需要在我的应用中显示任何图像或视频时,我需要横向模式才能更好地显示。
我可以通过以下方式检测设备方向变化
[[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;
};
}
但是,即使应用程序部署信息纵向被锁定,我如何手动更改我的设备方向?
这不起作用
NSNumber *value=[NSNumber numberWithInt: UIDeviceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];