[self presentModalViewController:controller animated:YES];表现得很奇怪 [英] [ self presentModalViewController: controller animated: YES ]; Behaves strangely

查看:98
本文介绍了[self presentModalViewController:controller animated:YES];表现得很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用应用程序,支持iPad中的所有方向,只支持iPhone / iPod中的potrait。我的代码看起来有点像这样:

I have an Universal App that supports all orientations in iPad and only potrait in iPhone / iPod. My code looks somewhat like this:

@implementation UIViewController ( interfaceOrientationHack )
  - (void) shouldAutorotateToInterfaceOrientation: ( UIInterfaceOrientation ) toInterfaceOrientation {
    if( iPad ) {
      return YES;
    } else if( toInterfaceOrientation == UIInterfaceOrientationPotrait ) { 
      return YES;
    } else return NO;
  }
@end

从我的一个控制器中,我启动导航控制器作为模态视图控制器

From one of my controllers, i launch a navigation controller as modal view controller

[ self presentModalViewController: c animated: YES ];

目前的问题是,模态控制器在方向上正确启动,但当我改变我的方向时模态控制器不会改变其方向,所有其他控制器的行为都正确。

The issue currently is, the modal controller launches correctly in orientation, But when i change my orientation the the modal controller doesn't change its orientation, all the rest of the controllers behave correctly.

任何帮助都将非常受欢迎。在此先感谢。

Any help will be hugely appreciated. Thanks in advance.

推荐答案

从UIViewcontroller类引用:默认情况下,UIViewController类仅以纵向模式显示视图。支持在其他方向上,您必须覆盖shouldAutorotateToInterfaceOrientation:方法,并为您的子类支持的任何方向返回YES。如果您的视图的自动调整属性配置正确,那么您可能只需执行此操作。

From UIViewcontroller class reference:"By default, the UIViewController class displays views in portrait mode only. To support additional orientations, you must override the shouldAutorotateToInterfaceOrientation: method and return YES for any orientations your subclass supports. If the autoresizing properties of your views are configured correctly, that may be all you have to do."

由于你的模态视图继承自UIViewcontroller,你必须在模态视图中覆盖shouldAutorotateToInterfaceOrientation :.

Since your modal view inherits from UIViewcontroller, you have to override shouldAutorotateToInterfaceOrientation:in your modal view.

这篇关于[self presentModalViewController:controller animated:YES];表现得很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆