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;
}
Related
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;
}
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;
}
How to use MPMoviePlayerController to play video in landscape orientation in iOS all across the Application. I am using the MPMoviePlayerController in many viewControllers of my app and I want all the MKMoviePlayerController torun only in landscape mode irrespective of the orientation of the parent view controller from where this ViewController is called.
Enable landscape orientation in your project settings.
Subclass UIViewController and in your new subclass (e.g. MyViewController) add these callbacks:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Make all your view controllers of type MyViewController.
In the views you want to force landscape override those methods with:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
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;
}
How to auto rotate first view only portrait and second view only landscape mode ios6
I tried like this in first view
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
in Second/Detail view
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL) shouldAutorotate{
return YES;
}
Firstly is this within a UINavigationController.
If so you should subclass UINavigationController and add the following to your subclass:
#pragma mark - Auto Rotation
-(BOOL)shouldAutorotate {
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
Then in each VC you can override the methods for which require and which do not require autorotation.