I know it's a common question but it seems i can't find the right solution that fits my needs.
Ok i've got a UIViewController (which parent view is a UINavigationController and then a UITabBarController) forced to be in a portrait mode. This guy has the ability to present modally another UIViewController which is been forced to stay in landscape mode when the user rotate the device. I've decided to use a manual segue to present this last guy. Here is the code for the presentation:
- (void)viewDidAppear:(BOOL)animated {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)orientationChanged:(NSNotification *)notification {
// Respond to changes in device orientation
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
[self performSegueWithIdentifier:@"gallerySegue" sender:self];
}
}
-(void) viewDidDisappear {
// Request to stop receiving accelerometer events and turn off accelerometer
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
To return to the first view controller i use these pieces of code
- (void)viewDidAppear:(BOOL)animated {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(returnBack:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void) viewDidDisappear {
// Request to stop receiving accelerometer events and turn off accelerometer
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
- (void)returnBack:(NSNotification *)notification {
// Respond to changes in device orientation
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
[self dismissViewControllerAnimated:NO completion:nil];
}
}
The warning is generated by the second view controller when i rotate the device.
WHY??
Thanks