我不希望我的应用程序被美化并始终是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;
};
}
但是,即使“应用程序部署信息”肖像被锁定,我如何手动更改设备方向?
这没有用
NSNumber *value=[NSNumber numberWithInt: UIDeviceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
请从您的项目设置中启用纵向和横向。然后使用以下方法为所有viewcontroller进行自动旋转-
- (BOOL)shouldAutorotate {
return NO;
}
然后对除LandScapeViewControler之外的所有其他对象使用以下方法-
- (void)viewWillAppear:(BOOL)animated {
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
对LandScapeViewControler使用以下方法-
- (void)viewWillAppear:(BOOL)animated {
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]
forKey:@"orientation"];
}
如果您使用的是NavigationController和TabBarController,请使用category关闭自动旋转。
希望这会对您有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句