强制横屏
NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
强制竖屏
NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown]; [[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@"orientation"];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@"orientation"];
⚠️
在执行上述方法时要重写controller的一下方法
//1,支持旋转
-(BOOL)shouldAutorotate{
return YES;
}
//2,支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
//所有方向
return UIInterfaceOrientationMaskAllButUpsideDown;
}