【发布时间】:2010-09-29 11:27:27
【问题描述】:
我根本无法触发UIDeviceOrientationDidChangeNotification。
我有我的 AppDelegate,在这里我添加了一个PolyOrientationViewController,它有一个UInavigationController,可以根据 iPad 的方向推送一个VerticalNavigationController 和一个HorizontalViewController。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ISPolyOrientationTableViewController *pvc = [[ISPolyOrientationTableViewController alloc] init];
[window addSubview:pvc.view];
[pvc release];
[window makeKeyAndVisible];
return YES;
}
Poly、Vertical 和 Horizontal viewController 实现:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
PolyVC,也就是最顶层的ViewController,它有这些方法:
- (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 通知?
我希望有人能指出我的错误:) 提前谢谢你。
【问题讨论】:
-
找到这个博客。它非常有用,简单且有效blog.sallarp.com/…
标签: ipad