This is a multifaceted question that can help those using Core Plot, or those who are having problems presenting a UIViewController modally, then trying to add it as a subview to a smaller UIView.
I have a Core Plot graph (corePlotView) added to a 500x350 UIView (myView) and am successfully presenting it "modally" using a long press:
-(void)press:(UILongPressGestureRecognizer*)gesture {
if(gesture.state == UIGestureRecognizerStateEnded)
{
corePlotView.closeBtn.hidden = NO;
corePlotView.iPadCV = self;
[corePlotView loadFullGraph];
[ipadDelegate.detailViewController presentViewController:corePlotView animated:NO completion:nil];
}
}
This is an easy way of making a full screen graph appear and still resize the graph when the iPad is rotated (very important). When the user clicks "closeBtn," a message is sent to dismissModalViewController from corePlotView...
-(IBAction)close:(id)sender {
self.closeBtn.hidden = YES;
ipadDelegate = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];
[ipadDelegate.detailViewController dismissViewControllerAnimated:NO completion:nil];
[iPadCV reloadOriginalGraph];
}
...then reloadOriginalGraph maintains all the plots and data the user had before presenting (important), then resizes the view back into its original frame like this:
-(void)reloadOriginalGraph {
[corePlotView.view setFrame:myView.bounds];
[corePlotView loadOriginalGraph];
[myView addSubview:corePlotView.view];
[myView sendSubviewToBack:corePlotView.view];
}
The [corePlotView loadOriginalGraph] and [corePlotView loadFullGraph] are calling methods that toggle all the text sizes and padding type properties from orginal settings to full screen settings...not the problem.
The problem is when the graph is sized back down successfully to 500x350, as soon as the iPad is rotated, the corePlotView resizes back to the frame of the modal view. Obviously, this isn't what I want, as the 500x350 needs to be maintained or constrained in some way.
Has anyone ran into this problem when presenting a modal then using addSubview? This method keeps the view live on the stack before ARC has a chance to remove it, but it seems like some attributes of the modal stay persistent. Are there ways to strip this "modality" from a UIViewController?
Is there an easier way to set a Core Plot graph to full screen and back again using gestures (seems like pinch gestures are not registered on the corePlotView, which is why I'm using a long press)?
The iOS hosting view uses a pinch gesture to allow pinch scaling of the plot space. If you'd rather have a different behavior, set the
allowPinchScaling
property of the hosting view toNO
to remove the default gesture recognizer.After working with presentViewController "enough," I decided that the best looking and safest way to make a Core Plot graph full screen was this:
IPHONE
IPAD
In this case, to avoid pinching conflicts, I used a long press gesture. Notice that for the iPad, appDelegate.splitViewController.view from a UISplitViewController. It was using a UIPopoverController that eliminated a ton of problems with view hierarchies and crashes when rotating in iOS 6.
NOTE: Careful with the iPhone code. I've found that if you have an app that doesn't rotate, except the corePlotVC, you might see occurrences of navBars falling behind the status bar. I'm working through that now, but this code can save a lot of people some time as is, so have at it.