为一个视图控制器强制景观ios
我已经看过类似问题的几个答案,但没有答案的工作。 我有一个应用程序,我需要一切的portait,除了我有一个照片浏览器。 在目标菜单的支持的方向部分,我只有肖像。 我怎么强迫我的一个观点是景观。 它从导航控制器被推到堆栈,但我使用故事板来控制所有这一切。
由于答案似乎隐藏在问题的评论中,而且由于ArunMak的回答相当混乱,我只是提供了我所发现的:
我所要做的就是把这个函数添加到我的自定义UIViewController子类的视图中:
- (NSUInteger)supportedInterfaceOrientations { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { // iPad: Allow all orientations return UIInterfaceOrientationMaskAll; } else { // iPhone: Allow only landscape return UIInterfaceOrientationMaskLandscape; } }
请注意,该项目需要允许所有方向(即:肖像,左侧风景,右侧风景 – 但绝不能在iPhone上颠倒!)。
如果你想限制一些或大部分视图到肖像,你需要在每一个视图控制器(或使用一个普通的超类,并从它的子类所有)实现上述方法 – 如果您限制设备方向在Info.plist只是肖像,应用程序将永远不会想到进入风景。
是的,这是可能的,你可以使用这个代码:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskLandscape; } -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { return orientation==UIInterfaceOrientationMaskLandscape; }
要么
在您的应用程序委托中尝试此方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if (sglobalorientation isEqualToString:@"AllOrientation"]) { return UIInterfaceOrientationMaskLandscape; } else { return UIInterfaceOrientationMaskAll; } }
在移动到横向视图控制器之前,需要将variables值sglobalorientation更改为该string值AllOrientation
并在你的横向视图控制器中,使用这个代码在你的视图中会出现
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft]; DigitalSignatureViewController *digisign = [[DigitalSignatureViewController alloc]init]; [self presentModalViewController:digisign animated:NO]; [self dismissModalViewControllerAnimated:NO]; - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return NO; }
再次当你移动到下一个视图控制器更改sglobalorientationstring值,并按照下一个视图控制器中的相同步骤。
让我们试试这个代码:
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight; self.navigationController.view.center = CGPointMake(([UIScreen mainScreen].bounds.size.width/2), [UIScreen mainScreen].bounds.size.height/2); CGFloat angle = 90 * M_PI / 180; self.navigationController.view.transform = CGAffineTransformMakeRotation(angle); self.navigationController.view.bounds = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.height , [UIScreen mainScreen].bounds.size.width);