Eva*_*ard 10 iphone orientation uinavigationcontroller viewcontroller ios
我已经看过类似问题的几个答案,但答案都没有.我有一个应用程序,我需要一切portait除了我有一个照片查看器.在目标菜单的支持方向部分,我只有肖像.如何强制我的一个视图成为风景.它正从导航控制器推入堆栈,但我正在使用故事板来控制所有这些.
Tho*_*ann 14
由于答案似乎隐藏在问题的评论中,并且由于ArunMak的回答很混乱,我只会提供我发现的内容:
我所要做的就是将这个函数添加到视图的自定义UIViewController子类中:
- (NSUInteger)supportedInterfaceOrientations {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// iPad: Allow all orientations
return UIInterfaceOrientationMaskAll;
} else {
// iPhone: Allow only landscape
return UIInterfaceOrientationMaskLandscape;
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,项目需要允许所有方向(即:纵向,横向左侧,横向右侧 - 但不要在iPhone上颠倒!).
如果要将某些或大多数视图限制为Portrait,则需要在每个视图控制器中实现上述方法(或者为它使用公共超类,并从中继承所有其他视图) - 如果限制设备方向Info.plist只是肖像,应用程序永远不会想到进入景观.
小智 2
是的,这是可能的,您可以使用以下代码:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
return orientation==UIInterfaceOrientationMaskLandscape;
}
Run Code Online (Sandbox Code Playgroud)
或者
在您的应用程序委托中尝试此方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (sglobalorientation isEqualToString:@"AllOrientation"]) {
return UIInterfaceOrientationMaskLandscape;
} else {
return UIInterfaceOrientationMaskAll;
}
}
Run Code Online (Sandbox Code Playgroud)
在移动到横向视图控制器之前,您需要将变量值 sglobalorientation 更改为该字符串值 AllOrientation
并在您的横向视图控制器中,使用此代码将出现在您的视图中
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
DigitalSignatureViewController *digisign = [[DigitalSignatureViewController alloc]init];
[self presentModalViewController:digisign animated:NO];
[self dismissModalViewControllerAnimated:NO];
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
Run Code Online (Sandbox Code Playgroud)
当您移动到下一个视图控制器时,再次更改 sglobalorientation 字符串值,并在下一个视图控制器中执行相同的步骤。
| 归档时间: |
|
| 查看次数: |
9642 次 |
| 最近记录: |