我根本无法让UIDeviceOrientationDidChangeNotification
着火。UIDeviceOrientationDidChangeNotification不会触发?
我有我的AppDelegate,在这里我想补充一个PolyOrientationViewController
,其中有一个UInavigationController
可以推VerticalNavigationController
和HorizontalViewController
根据对iPad的方向。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ISPolyOrientationTableViewController *pvc = [[ISPolyOrientationTableViewController alloc] init];
[window addSubview:pvc.view];
[pvc release];
[window makeKeyAndVisible];
return YES;
}
保利,垂直和水平的viewController实现:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
PolyVC,这是最上面的视图控制器,它有以下方法:
- (void)viewDidLoad {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[super viewDidLoad];
}
它具有相关功能:
- (void)didRotate:(NSNotification *)notification {
//push the related controller
}
在PolyVC实例化后,调用didRotate:
方法,从这里开始,它简单地停止生成UIDeviceOrientationDidChangeNotification
,我想。
我在didRotate:
方法中有一个断点,我已经将应用程序加载到iPad上以确保它不是模拟器的东西,我做了一个新的xcode splitViewController项目,测试了旋转工作,删除了代码并粘贴我已经检查了方向锁定按钮,我试过执行-(BOOL) ShouldAutoRotate…
我没有被调用,我检查了info.plist指定该应用程序支持所有方向,我尝试了复制粘贴每一条通知代码我找到了一个工作实例来清除拼写错误。我有一些我可以做的,一些实现UIViewController,不使用IB,在ViewControllers中嵌套ViewControllers(PolyViewController拥有UINavigationController,拥有Vertical和HorizontalViewController)或任何其他的东西将使应用程序完全忽略interfaceOrientation通知?
我希望有人能指出我的错误:) 先谢谢您。
找到这篇博客。这是非常有用的,简单和工作http://blog.sallarp.com/iphone-shouldautorotatetointerfaceorientation-breaking-changes/ – 2011-04-19 17:38:54