2015-05-21 13 views
6

Verwenden von CorePlot Version 1.6. Ausführen von iOS 8.3.iOS Core-Plot-Bildlauf funktioniert nicht gut

Ich verwende Core-Plot mit ScatterPlot für mehrere Zeilen darzustellen. Wenn ich blättern, bewegt sich der Graph zu Sprüngen und es wird gesperrt. Ich weiß nicht was passiert. Kannst du mir helfen? mein Code hier:

#import <UIKit/UIKit.h> 
#import "CorePlot-CocoaTouch.h" 
@interface TemporalLineViewController:UIViewController<CPTPlotDataSource, 
CPTScatterPlotDelegate> 

@property (strong, nonatomic) IBOutlet CPTGraphHostingView *hostingView; 

@end 


@interface TemporalLineViewController(){ 
    NSMutableDictionary *dates; 
} 
@property (nonatomic, readwrite, strong) NSArray *plotData; 
@end 

@implementation TemporalLineViewController 
-(CPTGraph *)createGraph{ 
    initWithFrame:CGRectMake(viewGraph.frame.origin.x, viewGraph.frame.origin.y, 500, viewGraph.frame.size.height)]; 

    CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:hostingView.bounds]; 
    [graph applyTheme:[CPTTheme themeNamed:kCPTSlateTheme]]; 
    hostingView.hostedGraph=graph; 

    // Axes 
    CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet; 
    CPTXYAxis *x   = axisSet.xAxis; 
    x.majorIntervalLength   = CPTDecimalFromDouble(ONEDAY); 
    x.orthogonalCoordinateDecimal = CPTDecimalFromDouble(0.0); 
    x.minorTicksPerInterval  = 0; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateFormat:@"dd/MM/yyyy"]; 
    CPTTimeFormatter *timeFormatter = [[CPTTimeFormatter alloc] initWithDateFormatter:dateFormatter]; 
    timeFormatter.referenceDate = [[NSDate alloc]init]; 
    x.labelFormatter   = timeFormatter; 
    x.labelRotation    = CPTFloat(M_PI_4); 

    CPTXYAxis *y = axisSet.yAxis; 
    y.hidden=YES; 
    y.orthogonalCoordinateDecimal = CPTDecimalFromInt(0); 
    return graph; 
} 

-(void)createScatterPlot{ 

    CPTGraph * graph = [self createGraph]; 

    CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace; 
    NSTimeInterval xLow  = 0.0; 
    plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(xLow) length:CPTDecimalFromDouble(ONEDAY * 10.0)]; 
    plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(-1) length:CPTDecimalFromDouble(5.0)]; 
    plotSpace.allowsUserInteraction = YES; 
    plotSpace.allowsMomentum = YES; 

    CPTScatterPlot *diagnosticPlot = [self createScatterPlotWithIdentifier:DIAGNOSTIC_PLOT withLineColor:[CPTColor greenColor] withFillColor:[CPTColor greenColor]]; 
    CPTScatterPlot *vaccinePlot = [self createScatterPlotWithIdentifier:VACCINE_PLOT withLineColor:[CPTColor blackColor] withFillColor:[CPTColor blackColor]]; 
    CPTScatterPlot *interventionPlot = [self createScatterPlotWithIdentifier:INTERVENTION_PLOT withLineColor:[CPTColor blueColor] withFillColor:[CPTColor blueColor]]; 
    CPTScatterPlot *smokingHabitPlot = [self createScatterPlotWithIdentifier:SMOKING_HABIT_PLOT withLineColor:[CPTColor yellowColor] withFillColor:[CPTColor yellowColor]]; 
    CPTScatterPlot *menstrualPlot = [self createScatterPlotWithIdentifier:MENSTRUAL_PLOT withLineColor:[CPTColor redColor] withFillColor:[CPTColor redColor]]; 
    CPTScatterPlot *menstrualTreatmentPlot = [self createScatterPlotWithIdentifier:MENSTRUAL_TREATMENT_PLOT withLineColor:[CPTColor orangeColor] withFillColor:[CPTColor orangeColor]]; 
    CPTScatterPlot *psychomotorMilestonePlot = [self createScatterPlotWithIdentifier:PSYCHOMOTOR_MILESTONE_PLOT withLineColor:[CPTColor purpleColor] withFillColor:[CPTColor purpleColor]]; 

    [graph addPlot:vaccinePlot toPlotSpace:plotSpace]; 
    [graph addPlot:diagnosticPlot toPlotSpace:plotSpace]; 
    [graph addPlot:interventionPlot toPlotSpace:plotSpace]; 
    [graph addPlot:smokingHabitPlot toPlotSpace:plotSpace]; 
    [graph addPlot:menstrualPlot toPlotSpace:plotSpace]; 
    [graph addPlot:menstrualTreatmentPlot toPlotSpace:plotSpace]; 
    [graph addPlot:psychomotorMilestonePlot toPlotSpace:plotSpace]; 
} 

-(CPTScatterPlot *)createScatterPlotWithIdentifier:(NSString *)identifier withLineColor:(CPTColor *)lineColor withFillColor:(CPTColor *) fillColor{ 
    CPTScatterPlot *dataSourceLinePlot = [[CPTScatterPlot alloc] init]; 
    dataSourceLinePlot.identifier = identifier; 

    CPTMutableLineStyle *lineStyle = [dataSourceLinePlot.dataLineStyle mutableCopy]; 
    lineStyle.lineWidth    = 3.0; 
    lineStyle.lineColor    = lineColor; 
    dataSourceLinePlot.dataLineStyle = lineStyle; 
    CPTPlotSymbol *plotSymbol2 = [CPTPlotSymbol ellipsePlotSymbol]; 
    plotSymbol2.fill    = [CPTFill fillWithColor:fillColor]; 
    plotSymbol2.size    = CGSizeMake(10.0, 10.0); 
    dataSourceLinePlot.plotSymbol = plotSymbol2; 

    return dataSourceLinePlot; 
} 

-(void)generateData{ 
    NSMutableArray *data = [NSMutableArray array]; 

    [data addObject:[self createDiagnosticData]]; 
    [data addObject:[self createVaccineData]]; 
    [data addObject:[self createInterventionData]]; 
    [data addObject:[self createSmokingHabitData]]; 
    [data addObject:[self createMenstrualData]]; 
    [data addObject:[self createMenstrualTreatmentData]]; 
    [data addObject:[self createPsychomotorMilestoneData]]; 
    self.plotData = data; 
} 

#pragma mark - 
#pragma mark Plot Data Source Methods 

-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot 
{ 
    NSLog(@"numberOfRecordsForPlot"); 
    if ([plot.identifier isEqual:DIAGNOSTIC_PLOT]) { 
     NSMutableArray *data = self.plotData[0]; 
     return data.count; 
    }else if([plot.identifier isEqual:VACCINE_PLOT]){ 
     NSMutableArray *data = self.plotData[1]; 
     return data.count; 
    } else if([plot.identifier isEqual:INTERVENTION_PLOT]){ 
     NSMutableArray *data = self.plotData[2]; 
     return data.count; 
    } else if([plot.identifier isEqual:SMOKING_HABIT_PLOT]){ 
     NSMutableArray *data = self.plotData[3]; 
     return data.count; 
    } else if([plot.identifier isEqual:MENSTRUAL_PLOT]){ 
     NSMutableArray *data = self.plotData[4]; 
     return data.count; 
    } else if([plot.identifier isEqual:MENSTRUAL_TREATMENT_PLOT]){ 
     NSMutableArray *data = self.plotData[5]; 
     return data.count; 
    } else if([plot.identifier isEqual:PSYCHOMOTOR_MILESTONE_PLOT]){ 
     NSMutableArray *data = self.plotData[6]; 
     return data.count; 
    } 
    return 0; 
} 

-(id)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index 
{ 
    NSLog(@"numberForPlot"); 
    if ([plot.identifier isEqual:DIAGNOSTIC_PLOT]) { 
     NSMutableArray *data = self.plotData[0]; 
     NSString *str = [NSString stringWithFormat:@"%@",(data[index][@(fieldEnum)])]; 
     if ([str intValue]==0) { 
      return nil; 
     } 
     return data[index][@(fieldEnum)]; 
    }else if([plot.identifier isEqual:VACCINE_PLOT]){ 
     NSMutableArray *data = self.plotData[1]; 
     NSString *str = [NSString stringWithFormat:@"%@",(data[index][@(fieldEnum)])]; 
     return data[index][@(fieldEnum)]; 
    }else if([plot.identifier isEqual:INTERVENTION_PLOT]){ 
     NSMutableArray *data = self.plotData[2]; 
     NSString *str = [NSString stringWithFormat:@"%@",(data[index][@(fieldEnum)])]; 
     return data[index][@(fieldEnum)]; 
    }else if ([plot.identifier isEqual:SMOKING_HABIT_PLOT]) { 
     NSMutableArray *data = self.plotData[3]; 
     NSString *str = [NSString stringWithFormat:@"%@",(data[index][@(fieldEnum)])]; 
     if ([str intValue]==0) { 
      return nil; 
     } 
     return data[index][@(fieldEnum)]; 
    }else if ([plot.identifier isEqual:MENSTRUAL_PLOT]) { 
     NSMutableArray *data = self.plotData[4]; 
     NSString *str = [NSString stringWithFormat:@"%@",(data[index][@(fieldEnum)])]; 
     if ([str intValue]==0) { 
      return nil; 
     } 
     return data[index][@(fieldEnum)]; 
    }else if ([plot.identifier isEqual:MENSTRUAL_TREATMENT_PLOT]) { 
     NSMutableArray *data = self.plotData[5]; 
     NSString *str = [NSString stringWithFormat:@"%@",(data[index][@(fieldEnum)])]; 
     if ([str intValue]==0) { 
      return nil; 
     } 
     return data[index][@(fieldEnum)]; 
    }else if([plot.identifier isEqual:PSYCHOMOTOR_MILESTONE_PLOT]){ 
     NSMutableArray *data = self.plotData[6]; 
     NSString *str = [NSString stringWithFormat:@"%@",(data[index][@(fieldEnum)])]; 
     return data[index][@(fieldEnum)]; 
    } 
    return nil; 
} 
+0

Haben Sie eine Lösung gefunden? – Iducool

+0

Endlich habe ich gefunden. In meinem Fall ist mein View-Controller im Dia-View-Controller und die Slide-Ansicht hat eine Schwenk-Geste. Diese Schwenkgeste widersprach Scroll. Wenn also jemand unter solchen Problemen leidet, dann suchen Sie nach Gesten oder nach einer benutzerdefinierten Berührungsereignisbehandlung. – Iducool

Antwort

0

Sie Ihre Scroll-Ansicht des Inhaltsgröße zurücksetzen? Wenn nicht, dann setze es auf ScatterPlots Framegröße zurück, wenn das nur innerhalb der Bildlaufansicht angezeigt wird.

+0

Ich habe keine Bildlaufansicht. Der Bildlauf ist der ScatterPlot. – oremag14jf

+0

Dann versuchen Sie das in UIScrollView einzuschließen? Oder ändern Sie den Rahmen des Streudiagramms so, dass es in Ihre Rahmengrenzen passen kann. – Rajesh

+0

Ich möchte es nicht in UIScrollView aufnehmen. Die Grafik zeigt gut, der Zoom funktioniert gut, aber wenn ich auf die andere Seite scrolle, stoppt der Scroll-Graph. – oremag14jf

Verwandte Themen