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)?