0

I am creating an application with Landscape Right orientation. For that I set the Initial interface orientation property in info.plist file. Then in every view I handled

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

It works fine in simulator but in device its behave differently. My first view is in proper orientation. There is is popover which display another view that comes in portrait mode. Still my status bar is in Landscape Right..

For navigating from one view to another view I am using..

self.window.rootViewController = self.myNav;

I have multiple navigation Controller and adding those using the upper code. I am not getting what is the problem.

Any help will be appreciated.

EDIT: I had used

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

I never get this issue in simulator but getting this in device and not every time. I have used Supported interface orientations (iPad) too and set Landscape (right home button) value for item0.

Thanks In advance

Kapil Choubisa
  • 5,152
  • 9
  • 65
  • 100

2 Answers2

3

You need to set the "Simulated Metrics > Orientation" property of your top view (in all your xib files) to be "Landscape". The default is portrait.

The question was answered pretty well here - Landscape Mode ONLY for iPhone or iPad .

I also have an app that like yours only supports UIInterfaceOrientationLandscapeRight. I haven't run into any orientation issues so far. I only have one UIViewController under the window. This UIViewController has its own UITabBar that I use to change pages. So, we change pages differently. I set my UIViewController using the rootViewController property of the window just like you, but again I only have one.

Also, I never had to do anything like the [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] call that you included. Since you only support LandscapeRight orientation, you shouldn't care to be notified of changes.

EDIT

I created a sample project, which I can post if necessary, and I think I may know your problem. First - do you only encounter the sizing issue inside popovers? If so, then I don't think orientation is throwing you off but the popover itself. My sample project has 3 view controllers. The first loads the second by changing the window's rootViewController. That worked fine. The second view controller has a button to open a popover. This will show up wrong unless you set the contentSizeForPopover on the view controller as shown below:

- (IBAction) showVC3InPopover
{
    UIViewController * vc3 = [[VC3 alloc] init];
    /** Set the contentSizeForViewInPopover property to determine how 
        large the view will be in the popover!  You can do this in the 
        init method(s) of the view controller if you prefer, it's just 
        easy to do here */
    vc3.contentSizeForViewInPopover = vc3.view.frame.size;
    [_popover release], _popover = nil;
    _popover = [[UIPopoverController alloc] initWithContentViewController:vc3];
    [vc3 release];

    [_popover presentPopoverFromRect:_showPopoverButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

See if this fixes your problem. If it does, there are other ways to control the popover size, but this is just what I typically do. However, just know that the PopoverController ignores the size of the view in the viewcontroller you load.

Community
  • 1
  • 1
Sam
  • 26,946
  • 12
  • 75
  • 101
  • I had already done with Making the xib files in landscape mode. It run fine with the first view. but when I add new view using `[self.window setRootViewController:self.navHome];` its getting problem in ios 4.2. – Kapil Choubisa Aug 18 '11 at 09:59
  • I'll make a sample project to try this out. – Sam Aug 18 '11 at 16:33
  • Where is the transition to the new view controller happening? Ex. Does ViewController 1 have a button (or something) that prompts the loading of ViewController 2? Normally you would have a UITabBar to change view controller pages like this. – Sam Aug 18 '11 at 18:43
  • I put my sample project here: http://www.tempfiles.net/download/201108/207606/LockedOrientation.html. It's small and simple, but I hope it will aid in our discussion and in helping you figuring out what is going on. If you could tweak the sample and get it to have the sample problems you are having and reupload, that would be ideal. – Sam Aug 18 '11 at 18:46
  • This issue is occurring only in ios version 4.2 same code is working fine in other ios version. ios 4.2 is not even creating issue every time.. still didn't get solved issue. – Kapil Choubisa Aug 23 '11 at 14:23
  • So, issue only occurs when 1.) you run it on an iPad (not simulator) and 2.) you build against the iOS 4.2 SDK. Is that right? Also, were you able to reproduce this problem with a sample project? Sample projects are a good idea because it isolates the problem and takes away code distrations. I'll try to dup your problem one last time in my sample project while building against the iOS 4.2 and running on my iPad 2. – Sam Aug 23 '11 at 16:46
  • Yes, you are right issue occurs only on the conditions we you told – Kapil Choubisa Aug 24 '11 at 15:41
1

How many views (or viewControllers) you have? You might need to implement this orientation logic in all those views??

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
  • I had done this already... I tried after using `[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];` I never get this issue in simulator but getting this in device and not every time.. – Kapil Choubisa Aug 11 '11 at 09:24