无法设置(使其更小)核心绘图饼图大小

时间:2012-05-09 17:44:56

标签: iphone cocoa-touch core-plot

是Core Plot& amp;的新手到iOS / Cocoa。我有一个视图,从中调用另一个具有CorePlot图形的视图(称为MyGraphView)。

MainView.h

@interface MainView:UIViewController { ... }

MainView.m

 ....
 ....
 @implementation MyView
 ....
 MyGraphView *myGraphView;
 ....
 ....
 // This gets called when a button's pressed. Once the button's pressed, 
 // I want to display the view which has the graph i.e. pie chart
 -(IBAction) toDateChosen:(id)sender {
   ....
    [self presentModalViewController:myGraphView animated:YES];
   ....
 }

 ....
 ....
 - (void)viewDidLoad {
    ...
    myGraphView = [[EmotionsHistoryView alloc] initWithNibName:nil bundle:nil];
    ....
 }

在MyGraphView.h中

#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"

@interface MyGraphView : UIViewController <CPTPlotDataSource> {
  ....
  ....
  CPTXYGraph *graph;
  CPTPieChart *pieChart;
}

@property (nonatomic, retain) CPTXYGraph *graph;

-(void) initializeGraph;
-(void) initializePieChart;
....
....

在MyGraphView.m

....
@implementation MyGraphView
....
-(void) initializeGraph {

    graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];

    CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
    hostingView.hostedGraph = graph;  
    //hostingView.bounds = CGRectMake(5, 5, 70, 70);
    [self initializePieChart];
}
....
....
-(void) initializePieChart {

    pieChart = [[CPTPieChart alloc] initWithFrame:CGRectMake(25, 25, 50, 20)];
    pieChart.dataSource = self;
    pieChart.pieRadius = 100.0;
    pieChart.opaque = FALSE;
    pieChart.pieRadius = 60;
    pieChart.shadowOffset = CGSizeMake(-1, 1);
    pieChart.identifier = @"Identifier1";
    pieChart.startAngle = M_PI_4;
    pieChart.sliceDirection = CPTPieDirectionCounterClockwise;
    pieChart.labelOffset = -0.6;
    [graph addPlot:pieChart];
}
....
....

当显示此图表视图时,我还想在图表下方显示一个按钮,该按钮将用户带到另一个屏幕。但我尝试了各种各样的方法,徒劳无功。我尝试使用视图框架的边界来减小图形大小,在图形和饼图的'init'中指定它,徒劳无功。该图似乎不可避免地占据了整个视图。我还尝试在MyGraphView.xib文件中添加一个按钮(在Interface Builder中),但是当我在iOS模拟器中运行应用程序时按钮没有显示,因为图形占据了整个视图/屏幕。

请指点什么? 我使用iOS 5.0和Xcode 4.2以及iOS模拟器来运行App。

谢谢

1 个答案:

答案 0 :(得分:1)

不要将按钮添加为主机视图的子视图。 Core Plot使用的翻转变换也会翻转按钮。而是同时创建另一个视图的主机视图和按钮子视图。它们可以像任何其他视图一样位于超视图中。