0
votes

My application is Navigation based.

All views are displaying Portrait mode except Report mode.Report mode display landscape mode when device is rotate landscape.

If device is rotate landscape mode Report view is displaying landscape mode.if report is landscape mode once again rotate in device Portrait mode it will display normal view of current view.

Flow of current action my view display. From current view is Portrait mode and i am rotating device in landscape mode so getting Landscape mode of Report mode. after two rotate only i am getting current view in Portrait mode. I need to reduce tow rotation . please guide me . How to check condition for after landscape mode of Report if once again rotate i need to display current view in Portrait mode.

Here at ReportViewController 


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    return UIInterfaceOrientationIsLandscape(interfaceOrientation);

}

@interface CurrentViewController

BOOL isShowingLandscapeView;
Report *landscapeViewController;

@implementation CurrentViewController 


- (void)viewDidLoad 
{
    [super viewDidLoad];

    Report *viewController = [[Report alloc]initWithNibName:@"Report" bundle:nil];
    self.landscapeViewController = viewController;
    [viewController release];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification object:nil];
}

- (void)orientationChanged:(NSNotification *)notification
{

    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}


- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
    {   

        [self presentModalViewController:self.landscapeViewController animated:YES];
        isShowingLandscapeView = YES;

    }
    else if(deviceOrientation == UIInterfaceOrientationPortrait && isShowingLandscapeView)
    {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }    
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return (interfaceOrientation == UIInterfaceOrientationPortrait ); // support only portrait

}
1

1 Answers

0
votes

I'm not sure I understand your question, but the code looks like it might have the logic reversed. In the ReportViewController,

- (BOOL)shouldAutorotateToInterfaceOrientation

is called before the rotation, so it should return YES for Portrait (YES, allow the view to rotate from Landscape TO portrait) and return NO for Landscape (NO, do not allow the view to rotate to Landscape from Landscape).

And similarly in CurrentVC - try

return (interfaceOriention==UIInterfaceOrientationLandscape);

Hope that helps. -Mike