Search code examples
iosobjective-ciphoneuiviewcontrolleruiinterfaceorientation

Present UIViewController in Landscape mode in Portrait only app


My app is a portrait only. I need to present a UIViewController in Landscape mode(Reason for that is I am using Core-Plot sdk for drawing graphs on that viewcontroller, so it needs to be in landscape mode).

I tried the following methods and it work fine. But the issue is, when I dismiss the landscape viewcontroller, app cannot force to portrait mode.

http://www.sebastianborggrewe.de/only-make-one-single-view-controller-rotate/

http://b2cloud.com.au/tutorial/forcing-uiviewcontroller-orientation/

How can I force the app to become portrait only mode after dismiss the landscape viewcontroller?

This is How I presenting the landscape view controller and dismissing it.

 LineChartViewController *obj = [[LineChartViewController alloc]initWithNibName:@"LineChartViewController" bundle:nil];

 [self.navigationController presentViewController:obj animated:YES completion:nil];  


- (IBAction)btnDonePressed:(id)sender{
    [self dismissViewControllerAnimated:NO completion:nil];
}

XIB of the LineChartViewController is in landscape mode.

In simple words, My app is portrait only, and I wanted to show CorePlot hostView in landscape mode.


Solution

  • Actually I could solve the issue by rotating the CorePlot hostView. The solution isn't the perfect for the the question described, but I'd like to put my solution here, since it solved my problem

    self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:self.viewGraphBack.bounds];
    self.hostView.allowPinchScaling = YES;
    [self.viewGraphBack addSubview:self.hostView];
    
    CGAffineTransform transform =
    CGAffineTransformMakeRotation(DegreesToRadians(90));
    
    viewGraphBack.transform = transform;
    
    viewGraphBack.frame = CGRectMake(-285, 0, 568, 320);
    
    [self.view addSubview:viewGraphBack];