Portrait VC should be presented modaly on Landscape VC - ios

I have a View Controller - A in Landscape Mode.
On top of it, I would like to present a View Controller - C in Portrait mode. Bellow, it there is a navigation VC - B.
For some reason, C is always landscape, even though I've added the following code:
-(BOOL)shouldAutorotate
{
return NO;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}

Related

View Controller present portrait random

I am presenting a view controller in landscape left mode. and its working fine. But i am facing a random issue where controller present portrait mode. I dont know why it is happening. i am using below code for rotate the view while presenting the view
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}

ios 7 orientation issue

In my App (deployment target iOS 7) for showing Pictures using Navigation Controller with root view controller (support portrait only)
[ pushes —> ]
Image view controller (support portrait & landscape)
In this image are shown using page View Controller
[ then presents —> ]
MPMovieplayer(support portrait & landscape)
on dismiss from movie player and popping to portrait only root view controller it turned to landscape.
I have given these in root view controller
-(BOOL)shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
I need this controller not going to landscape at any scenarios..
i have handled the orientation in Image View controller using the delegates
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
}
In Image view controller like this
- (BOOL)shouldAutorotate {
return YES;
}
Finally I got this fixed on using this checking in Appdelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
// Get topmost/visible view controller
UIViewController *currentViewController = [self.navigationController topViewController];
// Unlock landscape view orientations for this view controller
if([navigationController.topViewController isKindOfClass:[ImsgeViewController class]])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
else if([navigationController.topViewController isKindOfClass:[PageContentViewController class]])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
// Only allow portrait (standard behaviour)
return UIInterfaceOrientationMaskPortrait;
}

navigation between viewcontrollers when orientation changes

I am developing ios application that uses two viewcontrollers A and B. A supports both orientations landscape and portrait, when B is only in portrait mode. my goal is B viewcontroller always to be only in portrait mode when I navigate from A to B .I make restrictions on B viewcontroller in the navigationcontroller.
- (BOOL)shouldAutorotate
{
_navigation = (MBNavigationController *) self.frontViewController;
id currentViewController = [_navigation visibleViewController];
if ([currentViewController isKindOfClass:[MBViewController class]])
return NO;
return YES;
}
when A is in portrait orientation and I navigate to B everything works fine. but when A is in landscape mode and I do the same, part of the B controller view is out scenes. please help me to find the right solution.
One possible solution is present the B viewController with another navigationController in which
// sysversion>=ios6
- (BOOL)shouldAutorotate
{
return NO;
}
// sysversion<=ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}

iOS: Switching to Portrait ViewController from LandScape ViewController

I have a VC in Portrait which presents another VC that can either be portrait or landscape. The problem is that when I return back to the original VC that presented it, it is also shown in landscape until I rotate it and then it stays in portrait. What I want is to always have the original VC to always be portrait, how can I achieve this? Here it the code that I use to set up the VC orientations after I have set the supported orientations in my PList:
In the original VC, that should always be portrait
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
In my VC that could either be portrait or landscape, I have:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
Override the supportedInterfaceOrientations method and return UIInterfaceOrientationMaskPortraitUpsideDown.
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortraitUpsideDown;
}

return back from B VIewcontroller(Fixed Portrait), to A , A is not rotating to landscape mode automatically(Device is in Landscape Mode)

I hold device in landscape mode and moved into second view controller, which only support portrait mode. when return back from second view controller(Support all orientation), First view controller is not rotating to landscape mode automatically.
if i did below code then its work in IOS6. but not working for IOS7.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
[UIViewController attemptRotationToDeviceOrientation];
}
in IOS7 viewController is rotating but status bar is not rotating
Implement the following in VC A:
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
The solution presented by AMayes is not quite correct.
The UIViewController docs state the following:
Typically, the system calls this method only on the root view
controller of the window or a view controller presented to fill the
entire screen; child view controllers use the portion of the window
provided for them by their parent view controller and no longer
participate directly in decisions about what rotations are supported.
Therefore, put the following code in the UINavigationController subclass:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}

Resources