所以我有两个图块空间和一个图。一个是散点图,另一个是条形图。
目前,我已开启缩放(禁用Y轴)和平移的pan guest虚拟机识别器。
这是我的PlotSpace委托方法的代码。
#pragma mark -
#pragma mark PlotSpace Delegates
- (CGPoint)plotSpace:(CPTPlotSpace *)space willDisplaceBy:(CGPoint)proposedDisplacementVector{
return CGPointMake(0, 0);
}
- (BOOL)plotSpace:(CPTPlotSpace *)space shouldScaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint {
return YES;
}
- (CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate {
if (coordinate == CPTCoordinateX) {
[self checkIfCluster];
return [CPTPlotRange plotRangeWithLocation:newRange.location length:newRange.length];
} else {
if ([space.identifier isEqual: @"barplotspace"]) {
return [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat(10)]; //Look out for other one.
}
return [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0f) length:CPTDecimalFromFloat([self getMaxValue] * 1.25)]; //Look out for other one.
}
return nil;
}
- (void)plotSpace:(CPTPlotSpace *)space didChangePlotRangeForCoordinate:(CPTCoordinate)coordinate
{
[self updateStats];
}
-(void)handlePan:(UIPanGestureRecognizer *)sender{
CGPoint translation = [sender translationInView:self.view];
CPTXYPlotSpace *space = (CPTXYPlotSpace *)[self.hostView.hostedGraph defaultPlotSpace];
CGFloat movementDistance = space.xRange.lengthDouble / self.hostView.frame.size.width;
if (translation.x > 0) {
space.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(space.xRange.locationDouble - movementDistance * 30) length:space.xRange.length];
} else {
space.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(space.xRange.locationDouble + movementDistance * 30) length:space.xRange.length];
}
}
但是,我还在创建时将两个plotspaces的委托设置为self(定义了这些方法)。正在从条形图空间调用willChangePlotRangeTo
。不是willDisplaceBy
或shouldScaleBy
...这是奇怪的。我错过了什么吗?
答案 0 :(得分:0)
-plotSpace:willDisplaceBy:
委托方法仅在使用内置事件处理进行平移时从-pointingDeviceDraggedEvent:atPoint:
方法调用。
-plotSpace:shouldScaleBy:aboutPoint:
委托方法仅从-scaleBy:aboutPoint:
方法调用。内置捏合手势识别器使用此方法缩放绘图空间以响应手势。
答案 1 :(得分:0)
我忘记打开允许用户在两个图块空间上进行交互。