Reputation: 313
I have a problem where my first view controller is fixed to portrait. But the second view controller can be portrait or landscape. However, if I'm on the first view and hold the phone in landscape then go to the next view. The screen doesn't update it's orientation, but my code that manually places an item on the navbar does detect that it's in landscape.
So I have to re-rotate the device to make iOS realise it's changed.
Any ideas?!
Upvotes: 0
Views: 202
Reputation: 5424
You could try this in viewWillAppear
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
If the ViewController loads in portrait and the device is in landscape, it will forece a shift to landscape.
or you can show a modal that's forced to be in landscape, and remove it instantly, that will also force a shit.
[self presentViewController:PortraitVc animated:NO completion:^{
[PortraitVc dismissViewControllerAnimated:NO completion:nil];
}];
Upvotes: 0
Reputation: 3007
in your view controller which supports orientation add these method
-(BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return (UIInterfaceOrientationMaskAll);
}
and in appdelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;
if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}
return orientations;
}
Upvotes: 1
Reputation: 5424
You can use [[UIDevice currentDevice] orientation]. You also use the UIDevice instance to detect changes in the device’s characteristics, such as physical orientation.
You could detect that the physical orientation is landscape in your first viewcontroller, and then force the 2nd viewcontroller to load in landscape mode.
Upvotes: 0
Reputation: 13020
You can forcefully rotate the First ViewControlller to portaint
#import <objc/message.h>
-(void)viewDidAppear:(BOOL)animated{
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationPortrait );
}
Upvotes: 0