0

这是一个多方面的问题,可以帮助那些使用 Core Plot 的人,或者那些在以模式方式呈现 UIViewController 时遇到问题的人,然后尝试将其作为子视图添加到较小的 UIView 中。

我有一个核心绘图图(corePlotView)添加到一个 500x350 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];
    }
}

这是一种使全屏图形出现并在 iPad 旋转时仍然调整图形大小的简单方法(非常重要)。当用户单击“closeBtn”时,会从 corePlotView 向dismissModalViewController 发送一条消息...

-(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] 正在调用将所有文本大小和填充类型属性从原始设置切换到全屏设置的方法......不是问题。

问题是当图形成功缩小到 500x350 时,一旦 iPad 旋转,corePlotView 就会重新调整到模态视图的框架。显然,这不是我想要的,因为需要以某种方式维护或限制 500x350。

有没有人在呈现模态然后使用 addSubview 时遇到这个问题?此方法在 ARC 有机会将其删除之前将视图保持在堆栈上,但似乎模态的某些属性保持不变。有没有办法从 UIViewController 中去除这种“模态”?

有没有更简单的方法可以将 Core Plot 图形设置为全屏并使用手势再次返回(似乎捏手势未在 corePlotView 上注册,这就是我使用长按的原因)?

4

2 回答 2

1

iOS 宿主视图使用捏合手势来允许绘图空间的捏合缩放。如果您希望有不同的行为,请将allowPinchScaling托管视图的属性设置NO为删除默认手势识别器。

于 2013-03-07T02:24:44.607 回答
0

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

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

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.

于 2013-03-19T16:26:51.517 回答