我现在遇到的问题是,如果触摸图表我可以得到正确的Y值,那么你可以得到一个正确的Y值,但如果我放大,那么该值就会出错!
我尝试使用此功能来获得比例
-(BOOL)plotSpace:(CPTPlotSpace*)space shouldScaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint
但我得到的比例数不正确
每个人都请帮忙!!!
这是正确的屏幕截图:
这是错误的
-(BOOL)plotSpace:(CPTPlotSpace*)space shouldScaleBy:(CGFloat)interactionScale aboutPoint:(CGPoint)interactionPoint
{
NSDecimal plotPoint[2];
CPTXYPlotSpace *xySpace = (CPTXYPlotSpace *)space;
[xySpace plotPoint:plotPoint forPlotAreaViewPoint:interactionPoint];
NSLog(@"Dragg Event Scale: %f",real_scaleValue);
NSString *showingcontent_testing=[NSString stringWithFormat:@"Scale Y VAlue $:%f",
([[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPTCoordinateY]] doubleValue])];
return YES;
}
// This method is call when user touch & drag on the plot space.
- (BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDraggedEvent:(id)event atPoint:(CGPoint)point
{
if( ((self.view.frame.size.height- point.y+20)<324)
&&((self.view.frame.size.height- point.y+20)>22))
{
NSDecimal plotPoint[2];
CPTXYPlotSpace *xySpace = (CPTXYPlotSpace *)space;
[xySpace plotPoint:plotPoint forPlotAreaViewPoint:point];
NSLog(@"Dragg Event Scale: %f",real_scaleValue);
showingcontent=[NSString stringWithFormat:@"Price $:%f",
(([[NSDecimalNumber decimalNumberWithDecimal:plotPoint[CPTCoordinateY]] doubleValue])*real_scaleValue)-13.42623-5.573770-0.163934];
current_price_show.text=showingcontent;
[self.view bringSubviewToFront:current_price_show];
CGRect separator_line_frame = separator_line.frame;
separator_line_frame.origin.y =self.view.frame.size.height- point.y+20;
// final y destination
separator_line.frame = separator_line_frame;
[self.view bringSubviewToFront:separator_line];
}
return YES;
}
答案 0 :(得分:1)
在不同的绘图比例下转换值时遇到的问题是一个舍入问题。你得到了像素的触摸点。在任何绘图范围内只有有限数量的像素。如果放大,则增加任意两个给定值之间的像素数。
要将y轴向右移动,请缩小右边距,并确保托管视图填充屏幕宽度。