I simply can not get the UIDeviceOrientationDidChangeNotification
to fire.
I have my AppDelegate, here I add a PolyOrientationViewController
, which has a UInavigationController
that can push a VerticalNavigationController
and a HorizontalViewController
depending on the orientation of the iPad.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
IS开发者_开发技巧PolyOrientationTableViewController *pvc = [[ISPolyOrientationTableViewController alloc] init];
[window addSubview:pvc.view];
[pvc release];
[window makeKeyAndVisible];
return YES;
}
Poly, Vertical and Horizontal viewController implements:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
PolyVC, which is the top most ViewController, it has these methods:
- (void)viewDidLoad {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[super viewDidLoad];
}
It has the function related:
- (void)didRotate:(NSNotification *)notification {
//push the related controller
}
Upon the instantiation of the PolyVC, the didRotate:
method is called, from here on it simply stops generating the UIDeviceOrientationDidChangeNotification
, I think.
I have a breakpoint in the didRotate:
method, I have loaded the app onto an iPad to make sure it was not a simulator thing, I have made a new xcode splitViewController project, tested the rotation worked, deleted the code and pasted my own, I have checked the orientation-lock button, I have tried implementing the -(BOOL) ShouldAutoRotate…
I is neither called, I checked that the info.plist specifies that the app supports all the orientations, I have tried copy pasting every piece of notification code from a working example I found to weed out typos.
I am completely at my wits end here:) Is there something I could have done, some way of implementing a UIViewController, not using IB, nesting ViewControllers inside ViewControllers (PolyViewController owns UINavigationController that owns Vertical and HorizontalViewController) or anything that will make the app completely ignore interfaceOrientation notifications?
I hope someone can point out my mistake :) Thank you in advance.
Extracted from the documentation, try if it helps:
You get the current orientation using the orientation property or receive change notifications by registering for the UIDeviceOrientationDidChangeNotification notification. Before using either of these techniques to get orientation data, you must enable data delivery using the beginGeneratingDeviceOrientationNotifications method. When you no longer need to track the device orientation, call the endGeneratingDeviceOrientationNotifications method to disable the delivery of notifications.
This symptom (notification fired once at initialization then stops) sounds like because you've deactivated orientation change in your iPhone. That's what happened to me anyway.
精彩评论