开发者

How to make core plot auto change orientation when device is rotated?

I'm trying to have core plot to automatically redraw a b开发者_如何学Goar chart when orientation is changed just like in the provided example (CPTTest-iphone). I made some search on google but no luck. I do have the the CPTGraphHostingView property autoresizingMask set to true and in the nib file its view mode is set to "Scale to Fill". Any ideas what I'm doing wrong or other configuration i am missing? Thank you.


When you detect an orientation change, you need to change the dimensions of your CPTGraphHostingView, then call reloadData on all the plots in your graph. Something like this:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    self.hostingView.frame = CGRectMake( /* new dimensions for your hosting view */ );
    for (CPTPlot *p in self.graph.allPlots)
    {
        [p reloadData];
    }
}

You might also need to fix up the labels and tick marks on your axes, and the padding on the plotAreaFrame to accommodate the new size of the hosting view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜