0

CorePlotと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シミュレーターでアプリを実行すると、グラフがビュー/画面全体を占めるため、ボタンが表示されません。

何かポインタをお願いしますか?私はiOS5.0とXcode4.2を、iOSシミュレーターと一緒に使用してアプリを実行しています。

ありがとうございました

4

1 に答える 1

1

ホスティング ビューのサブビューとしてボタンを追加しないでください。Core Plot で使用される反転変換もボタンを反転します。代わりに、別のビューのホスティング ビューとボタン サブビューの両方を作成します。これらは、他のビューと同様にスーパービューに配置できます。

于 2012-05-09T23:03:45.567 に答える