Utilisation de l'interaction de l'utilisateur par défaut ne suffisait pas pour moi parce que:
- Il adapte les deux X & axe Y en même temps et je voulais seulement à l'échelle axe X
- Pan ne vous permet pas d'aller passé zéro et il saute et ne fonctionne pas fondamentalement droit ..
Ma solution était de faire moi-même
I ajouté 2 UIGestureRecognizer Pan, Zoom
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panChart:)];
[pan setMinimumNumberOfTouches:1];
[pan setMaximumNumberOfTouches:1];
[self.view addGestureRecognizer:pan];
UIPinchGestureRecognizer* scale = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleChart:)];
[self.view addGestureRecognizer:scale];
Je puis mis en œuvre le code pour faire ce que je devais
Pan Graphique
- (void)panChart:(UIPinchGestureRecognizer *)gestureRecognizer {
CPTGraph *theGraph = [graphs objectAtIndex:0];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)theGraph.defaultPlotSpace;
CGPoint point = [gestureRecognizer locationInView:self.view];
if([(UIPanGestureRecognizer*)gestureRecognizer state] == UIGestureRecognizerStateBegan) {
firstX = point.x;
firstY = point.y;
originX = chartBounds.origin.x;
originY = chartBounds.origin.y;
//NSLog(@"first (%f,%f)", firstX, firstY);
}
CGRect frame = theGraph.frame;
float xMove = ((firstX-point.x)/(frame.size.width/chartBounds.size.width));
float yMove = ((firstY-point.y)/(frame.size.height/chartBounds.size.height));
if(firstX-point.x == 0){
xMove = 0;
}
if(firstY-point.y == 0){
yMove = 0;
}
//NSLog(@"frame: (%f, %f)",frame.size.width, frame.size.height);
//NSLog(@"touch (%f,%f)",firstX-point.x,firstY-point.y);
//NSLog(@"move (%f,%f)",xMove,yMove);
chartBounds.origin.x = originX+xMove;
chartBounds.origin.y = originY-yMove;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(chartBounds.origin.x) length:CPTDecimalFromFloat(chartBounds.size.width)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(chartBounds.origin.y) length:CPTDecimalFromFloat(chartBounds.size.height)];
}
échelle graphique
- (void)scaleChart:(UIPinchGestureRecognizer *)gestureRecognizer {
if (kMaxDataPoints < kDataPointsHistory) {
if ([gestureRecognizer scale] < 1) {
if(kMaxDataPoints/10 < 1){
kMaxDataPoints += 1;
}else{
kMaxDataPoints += kMaxDataPoints/10;
}
}
}
if (kMaxDataPoints > 5) {
if ([gestureRecognizer scale] > 1){
if(kMaxDataPoints/10 < 1){
kMaxDataPoints -= 1;
}else{
kMaxDataPoints -= kMaxDataPoints/10;
}
}
}
if(kMaxDataPoints <= 5){
kMaxDataPoints = 5;
}
if(kMaxDataPoints > kDataPointsHistory){
kMaxDataPoints = kDataPointsHistory;
}
chartBounds.size.width = kMaxDataPoints;
CPTGraph *theGraph = [graphs objectAtIndex:0];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)theGraph.defaultPlotSpace;
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(chartBounds.origin.x) length:CPTDecimalFromFloat(chartBounds.size.width)];
//Need to calculate if its horizontal or vertical pinch gesture (not doing that yet :))
//plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(chartBounds.origin.y) length:CPTDecimalFromFloat(chartBounds.size.height)];
}
où u r appeler ces méthodes? – Pooja
avec cette méthode je vois que le zoom n'est pas centré, il y a un moyen de zoomer le centre de l'intrigue? – kikko088