2013-02-07 34 views
0

我正在使用代碼here的修改版本來顯示沿着曲線圖中點的標註彈出窗口。我主要工作,但我遇到的問題是,當我滾動或縮放圖形時,標註停留在屏幕上的相同位置,而不是隨着點的移動而跟隨。來自Core Plot的標註不會滾動

如果你想要一些代碼示例來玩,在這裏他們是。關於如何使標註符合情節點的任何想法?謝謝!

-(void)scatterPlot:(CPTScatterPlot *)plot plotSymbolWasSelectedAtRecordIndex:(NSUInteger)idx { 
    if ([plot.identifier isEqual:_plotIdentifier]) { 

     NSArray *selectedSymbolItem = [self.data.xyArrays objectAtIndex:idx]; 
     NSNumber *x = [selectedSymbolItem objectAtIndex:0]; 
     NSNumber *y = [selectedSymbolItem objectAtIndex:1]; 
     double doublePrecisionPlotPoint[2]; 
     doublePrecisionPlotPoint[0] = x.doubleValue; 
     doublePrecisionPlotPoint[1] = y.doubleValue; 
     CGPoint pointTouched = [plot.graph.defaultPlotSpace plotAreaViewPointForDoublePrecisionPlotPoint:doublePrecisionPlotPoint]; 

     CGPoint convertedPoint = [plot.graph convertPoint:pointTouched toLayer:self.view.layer]; 

     _popupView = [[SMCalloutView alloc] init]; 
     _popupView.title = [NSString stringWithFormat:@"Thing %i", idx]; 
     [_popupView presentCalloutFromRect:CGRectMake(convertedPoint.x, convertedPoint.y, 10, 10) inLayer:self.view.layer constrainedToLayer:self.hostView.layer permittedArrowDirections:SMCalloutArrowDirectionDown animated:YES]; 

    } 
} 

回答

1

使用繪圖空間代表來監視繪圖空間的更改並根據需要更新繪圖位置。

+0

啊,好主意!我會給你一個鏡頭,讓你知道它是怎麼回事! – guthook

+0

剛剛在plotSpace:willChangePlotRangeTo:forCoordinate委託方法中添加了上述代碼的稍微修改後的版本,並且它工作得很好。當我滾動時,SMCalloutView會閃爍,因爲我最終會在滾動時爲動畫屬性調用presentCalloutFromRect,但除此之外,一切正常。謝謝! – guthook