我的要求是,在拖动垂直线时 - 它应该与< >箭头按钮。右端的视图变为绿色透明。 我的问题是,有时当我拖动垂直线时,线条,按钮是错误对齐的,如图2所示。任何人都可以帮助解决我的问题。
绘制线拖动事件的实现。enter code here
- (BOOL)plotSpace:(CPTPlotSpace *)space shouldHandlePointingDeviceDraggedEvent:(id)event atPoint:(CGPoint)point
{
CPTScatterPlot *freqRolPlot = (CPTScatterPlot *)[self.curveEditingGraphView.hostedGraph plotAtIndex:2];
CGPoint pointInPlotArea = [self.curveEditingGraphView.hostedGraph convertPoint:point toLayer:self.curveEditingGraphView.hostedGraph.plotAreaFrame];
NSInteger indexVal = [thePlot indexOfVisiblePointClosestToPlotAreaPoint:pointInPlotArea];
if(pointInPlotArea.x <=24)
{
indexVal = 0;
pointInPlotArea.x = 14.0f;
}
NSDictionary* num = [self.editableGraphData objectAtIndex:indexVal];
if(pointInPlotArea.x <=24)
{
freqRollCoordinate = 20;
}
else{
freqRollCoordinate = [[num objectForKey:@"x"] integerValue];
}
[self showDisabledView:pointInPlotArea.x];
[self showFreqRolAnnotation:freqRollCoordinate:pointInPlotArea.x];
[freqRolPlot reloadData];
return YES;
}
-(void)showDisabledView:(float)selectedAreaXPos
{
CPTGraph *graph = self.curveEditingGraphView.hostedGraph;
if (self.maskAnnotation ) {
[graph.plotAreaFrame.plotArea removeAnnotation:self.maskAnnotation];
self.maskAnnotation = nil;
[nxtBtn removeFromSuperview];
[prevBtn removeFromSuperview];
}
prevBtn = [UIButton buttonWithType: UIButtonTypeCustom];
prevBtn.frame = CGRectMake(selectedAreaXPos-7,18,30,30);
UIImage *btnImage = [UIImage imageNamed:@"PrevbtnImg"];
[prevBtn setImage:btnImage forState:UIControlStateNormal];
nxtBtn = [UIButton buttonWithType: UIButtonTypeCustom];
nxtBtn.frame = CGRectMake(3,15,30,30);
UIImage *nxtImage = [UIImage imageNamed:@"NextbtnImg"];
[nxtBtn setImage:nxtImage forState:UIControlStateNormal];
CGRect imageRect = CGRectMake(selectedAreaXPos,0,self.curveEditingGraphView.hostedGraph.bounds.size.width-selectedAreaXPos,self.curveEditingGraphView.hostedGraph.bounds.size.height);
CPTBorderedLayer * imageLayer = [[CPTBorderedLayer alloc] initWithFrame:imageRect];
CPTColor *transparentGreen = [[CPTColor greenColor] colorWithAlphaComponent:CPTFloat(0.4)];
CPTFill* areaFill = [[CPTFill alloc] initWithColor:transparentGreen];
imageLayer.fill = areaFill;
[imageLayer addSublayer:nxtBtn.layer];
self.maskAnnotation =[[CPTPlotSpaceAnnotation alloc] initWithPlotSpace:graph.defaultPlotSpace anchorPlotPoint:nil];
self.maskAnnotation.contentLayer = imageLayer;
[graph addSublayer:prevBtn.layer];
[self.curveEditingGraphView.hostedGraph.plotAreaFrame.plotArea addAnnotation:self.maskAnnotation];
}