0

I have app for iPhone and it's done. This works only for potrait mode.

Client need an update saying whenever user browse photo/ watch video, he need landscape mode too so that when he rotate image or video, it will get full screen.

For this I ticked all four Device Orientation.

enter image description here

Then based on this answer, I made custom navigation controller file and assigned it.

.h file

#import <UIKit/UIKit.h>

@interface CustomNavigationController : UINavigationController

@end

.m file

#import "CustomNavigationController.h"

@interface CustomNavigationController ()

@end


@implementation CustomNavigationController

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

@end

Now when I run app and rotate to landscape, still I see potrait mode only.

Till now this is fine.

Now what I want to do is, for some screens, I want landscape mode too. Any idea how can I do the same?


Edit 2

When I hide what I have in CustomNavigationController, and try to rotate iPhone, the image is also rotating. This is happening because I have hidden the code which says "I am not allowing for rotation" return NO.

So is there any way where I can say for the images, also allow iphone to go to landscape mode?

For photo browsing, I am using https://github.com/mwaterfall/MWPhotoBrowser

Community
  • 1
  • 1
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
  • 1
    possible duplicate of [Support different orientation for only one view iOS 6](http://stackoverflow.com/questions/12772749/support-different-orientation-for-only-one-view-ios-6) – Jorge Y. C. Rodriguez Jan 13 '14 at 11:18
  • why cant u force rotate the view?I have one question like this.I am force rotating the view for printlayout to landscape whatever be the previous view the current view will be force set to landscape.you can try that. link for the answer.. http://stackoverflow.com/questions/21019908/force-set-landscape-orientation-is-not-working-in-xib/21020567#21020567 – iOSdev Jan 13 '14 at 11:32
  • @NarasimhaiahKolli : I don't want forced. Both orientation should support... potrait or landscape.... – Fahim Parkar Jan 13 '14 at 11:38
  • In didchange interface orientation use some animation and check for the device orientation and rotate programatically.this could help you right. – iOSdev Jan 13 '14 at 12:26

1 Answers1

3

When we are talking about orientation, they are 2 things that come into the picture:

  1. Device Orientation
  2. Interface Orientation

As its clear by the name only, Device orientation tells, in which orientation device is, and Interface orientation says in which orientation your app is presenting its interface.

"Client need an update saying whenever user browse photo/ watch video, he need landscape mode too so that when he rotate image or video, it will get full screen."

By this, its clear that you don't need to change interface of your App. What you need is to rotate the image, when device orientation changes.

For that, First thing you should do is, have a look at this method beginGeneratingDeviceOrientationNotifications

Write this to get notified each time when Device orientation is changed [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

Now, in the viewController where you are showing the images/videos, write this

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];

In deviceOrientationDidChange method, rotate the image as per device orientation Let me know if more info needed..

Edit: There are 4 orientations possible:

  • UIInterfaceOrientationLandscapeLeft
  • UIInterfaceOrientationPortrait
  • UIInterfaceOrientationLandscapeRight &
  • UIInterfaceOrientationPortraitUpsideDown

As you said you are using MPMoviePlayerController, that supports Landscape Mode. Your code should not depend on which orientation the player is supporting, which its not. You should write code in such a way that it should support all the orientation.

So, as I said earlier, In deviceOrientationDidChange method, rotate the image as per device orientation.

Let me know if still some issues are there.

EDIT 2: First of all uncheck all orientation support (Except portrait one). Now you don't have to change interface orientation in your code. What you have to do is, you have to detect device orientation change & rotate image like this:

myImage.transform = CGAffineTransformMakeRotation(M_PI + M_PI_2);

I don't think you need customNavigationController to do that. Just try the steps I told you with default NavigationController. It's working fine for me for similar app. Try it with a demo application & then do necessary updates in your main App. Still, Let me know if you get stuck somewhere. :)

Prince Agrawal
  • 3,619
  • 3
  • 26
  • 41
  • when watching video OR see image, all 4 orientation should support... For video, I was using MPMoviePlayerController and landscape is working... – Fahim Parkar Jan 13 '14 at 11:37
  • Edited answer. Check it @FahimParkar – Prince Agrawal Jan 13 '14 at 11:59
  • see, if I hide what I am writing in CustomNavigationController, and rotate the iPhone, image also get rotated... but when I have this code its not rotating... I want to make this working... – Fahim Parkar Jan 13 '14 at 12:06
  • Didn't get you.. @FahimParkar – Prince Agrawal Jan 13 '14 at 12:07
  • let me be more clear... Let's say I am not using CustomNavigationController that I created. Now my iPhone is supporting both orientations. When I rotate my screen, I see landscape mode (but with ugly design as I have design for potrait mode only)... Now when I use landscape mode for image viewing, I see images in landscape mode.... To avoid ugly design, I am using customnavigationcontroller... now for images view controller only, I want to activate landscape mode TOO so that i can see images in landscape format... – Fahim Parkar Jan 13 '14 at 12:12
  • @FahimParkar Once check the answer – Prince Agrawal Jan 13 '14 at 12:18
  • k. give it some time. Read the answer next day & if you are not clear with it, ping me anytime. Goodnight :) – Prince Agrawal Jan 13 '14 at 12:27