核心图 – 使graphics全屏显示的选项 – 显示模态问题后的addSubview

这是一个多方面的问题,可以帮助那些使用核心绘图,或者有问题呈现一个UIViewController模态,然后试图将其作为子视图添加到一个较小的UIView。

我有一个核心图(corePlotView)添加到一个500×350 UIView(myView),并成功地使用长按“模态”显示:

-(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]; } } 

这是一个简单的方法,使全屏幕graphics出现,并仍然调整图表时,iPad旋转(非常重要)。 当用户点击“closeBtn”时,将发送消息从corePlotView中closuresModalViewController…

 -(IBAction)close:(id)sender { self.closeBtn.hidden = YES; ipadDelegate = (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate]; [ipadDelegate.detailViewController dismissViewControllerAnimated:NO completion:nil]; [iPadCV reloadOriginalGraph]; } 

…然后reloadOriginalGraph维护用户在呈现(重要)之前所有的图表和数据,然后将视图重新调整回原始框架,如下所示:

 -(void)reloadOriginalGraph { [corePlotView.view setFrame:myView.bounds]; [corePlotView loadOriginalGraph]; [myView addSubview:corePlotView.view]; [myView sendSubviewToBack:corePlotView.view]; } 

[corePlotView的loadOriginalGraph]和[corePlotView的loadFullGraph]调用的方法,将原始设置的所有文本大小和填充types属性切换到全屏设置…不是问题。

问题是,当graphics的大小成功回落到500×350时,只要iPad旋转,corePlotView就会调回到模态视图的框架。 显然,这不是我想要的,因为500×350需要以某种方式维护或约束。

有没有人遇到这个问题时,呈现模式,然后使用addSubview? 在ARC有机会删除它之前,这个方法保持视图在栈上,但是看起来像模态的某些属性保持不变。 有没有办法从UIViewController中去除这个“模态”?

是否有一个更简单的方法来设置一个核心绘图graphics全屏幕和使用手势再次回来(似乎捏手势没有注册在corePlotView,这就是为什么我使用长按)?

iOS托pipe视图使用捏手势来允许绘图空间的缩放比例。 如果您宁愿有不同的行为,请将托pipe视图的allowPinchScaling属性设置为NO以删除默认的手势识别器。

在使用presentViewController“足够”之后,我决定将整个屏幕绘制成Core Plotgraphics的最好看和最安全的方法是:

苹果手机

 -(void)press:(UILongPressGestureRecognizer*)gesture { if(gesture.state == UIGestureRecognizerStateEnded) { [corePlotVC removeFromParentViewController]; vc = [[UINavigationController alloc] initWithRootViewController:corePlotVC]; vc.navigationBar.hidden = YES; corePlotVC.closeBtn.hidden = NO; corePlotVC.view.autoresizingMask = UIInterfaceOrientationMaskAll; [corePlotVC loadFullGraph]; [details presentViewController:vc animated:NO completion:nil]; [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade]; } } 

IPAD

 -(void)press:(UILongPressGestureRecognizer*)gesture { if(gesture.state == UIGestureRecognizerStateEnded) { [corePlotVC removeFromParentViewController]; popover = [[UIPopoverController alloc] initWithContentViewController:corePlotVC]; [popover setPopoverContentSize:CGSizeMake(1024, 1024)]; popover.passthroughViews=[NSArray arrayWithObject:appDelegate.splitViewController.view]; [popover presentPopoverFromRect:CGRectZero inView:appDelegate.splitViewController.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; corePlotVC.closeBtn.hidden = NO; [corePlotVC loadFullGraph]; } } 

在这种情况下,为了避免捏造冲突,我使用了长按手势。 请注意,对于iPad,从UISplitViewController获取appDelegate.splitViewController.view。 它使用了一个UIPopoverController,消除了在iOS 6中旋转的视图层次和崩溃问题。

注:小心与iPhone代码。 我发现如果你有一个不旋转的应用,除了corePlotVC,你可能会看到navBars出现在状态栏的后面。 我正在通过这个工作,但是这个代码可以节省很多人的时间。