补充道:,我看到我的问题经常被浏览而没有得到支持,所以我决定你们不会得到你们搜索的东西。重定向到有关于How to handle orientation changes in iOS6的很好答案的问题
对定位更改的具体要求:Restricted rotation
欢迎投票:)
我已经创建了一个新的项目,从主细节模板,并试图开始它的景观定位。如你所知
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法是不推荐的,我们必须使用
- (NSUInteger)supportedInterfaceOrientations
和/或
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
这是我的密码:
- (NSUInteger)supportedInterfaceOrientations {
NSLog(@"supported called");
return UIInterfaceOrientationMaskAll;//Which is actually a default value
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
NSLog(@" preferred called");//This method is never called. WHY?
return UIInterfaceOrientationLandscapeRight;
}正如您所看到的,我正在尝试以首选的方法返回景观方向,但从来没有调用过它。附注:文件规定:
讨论了在显示视图控制器全屏时,系统调用该方法的方法。当视图控制器支持两个或多个方向时,实现此方法,但内容在其中一个方向中显示得最好。 如果您的视图控制器实现了这个方法,那么当显示它时,它的视图将以首选的方向显示(尽管它以后可以旋转到另一个受支持的旋转方向)。如果不实现此方法,系统将使用状态栏的当前方向显示视图控制器。
因此,问题是:为什么从来不调用prefferredOrientation方法?我们应该如何处理不同控制器的不同方向?谢谢!P.S不要把问题标记为重复。我调查过所有类似的问题,但他们对我的问题没有答案。
发布于 2013-02-13 13:24:19
如果您希望在景观模式下启动模式视图,只需将此代码放在呈现视图控制器中即可。
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
UIInterfaceOrientation orient = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsLandscape(orient)) {
return orient;
}
return UIInterfaceOrientationLandscapeLeft;
}然后,像往常一样呈现这个控制器。
UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self.navigationController presentViewController:vc animated:YES completion:^{}];发布于 2015-03-24 13:30:17
有一个非常简单的答案:您只能更改或修复模态呈现视图控制器的接口方向。如果这样做,即在接口构建器(或导航控制器方法)中使用当前模式segue,则可以使用
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait; // for example else an addition of all allowed
}当您只在导航控制器上推送视图控制器时,此事件不会触发。所以:你没有后退按钮,你需要一个
[self dismissViewControllerAnimated:YES completion: ^(void) {
}];关闭它。
https://stackoverflow.com/questions/12778636
复制相似问题