开发者

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

开发者 https://www.devze.com 2023-04-05 13:50 出处:网络
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 luc

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

精彩评论

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

关注公众号