私は、いくつかの行を表示する簡単なチャートコントロールを持っています。グラフの絵に関わる3つのプロパティがあります。UIPinchGestureRecognizer正しい使い方は?
RecordCount
FirstVisibleIndex
LastVisibleIndex
すべてがOK、チャートはまず&最終可視録音の間だけで罰金を描いて動作します。 今私は&を2本の指でチャートにズームアウトさせたいので、私はUIPinchGestureRecognizer
を購読してそのようなルーチンを実装しました。
-(void)handleZoomGesture:(UIGestureRecognizer *)sender
{
if (_isChartBusy) {
return;
}
UIPinchGestureRecognizer *gr = (UIPinchGestureRecognizer*)sender;
if (gr.state != UIGestureRecognizerStateChanged && gr.state != UIGestureRecognizerStateEnded)
return;
CGFloat scale = gr.scale;
if (scale == 1) {
return ;
}
if (_prevZoomScale == 0) {
_prevZoomScale = scale;
return;
}
int startIndex = chart.FirstVisibleIndex;
int endIndex = chart.LastVisibleIndex;
NSLog(@"Zoom. Scale: %f", scale);
int stepZoom;
int cnt = chart.LastVisibleIndex - chart.FirstVisibleIndex;
stepZoom = cnt * 0.05;
if (scale < _prevZoomScale) {
startIndex -= stepZoom;
endIndex += stepZoom;
} else {
startIndex += stepZoom;
endIndex -= stepZoom;
}
_prevZoomScale = scale;
if (endIndex < startIndex || (endIndex - startIndex) < 10) {
return;
}
if (startIndex < 0) {
startIndex = 0;
}
if (endIndex >= [chart.DataProvider GetBarRecordCount]) {
endIndex = [chart.DataProvider GetBarRecordCount] - 1;
}
if (startIndex == chart.FirstVisibleIndex && endIndex == chart.LastVisibleIndex) {
return;
}
chart.FirstVisibleIndex = startIndex;
chart.LastVisibleIndex = endIndex;
[self setNeedsDisplay];
}
それはちょっと動作しますが、私は指を動かすと、ズーム操作を行うためにしようとすると非常に不安定、チャートは「びくびく」を取得します。 &の経験があり、すてきで滑らかなズームをシミュレートできません。 VisibleIndexesのようなスムーズな変更を実現するための最良の方法は、チャート内のレコード数と表示可能なレコード数に関連します。
質問は、パフォーマンスについては、チャート塗料はかなり高速です。私の問題は、スムーズなズームイン&アウトエクスペリエンスを実現するために、ジェスチャーコールバック内にあるチャートプロパティを正しく操作する方法です。 – Eugen
何をチャートに使用していますか?あなたはCore Graphicsで直接描画していますか – MobileOverlord
はい、私はQuartzを使って描画しますが、それは描画に関するものではありません。ジェスチャーコールバックで取得した値を使用してプロパティ(FirstVisibleIndex、LastVisibleIndex)を正しく計算する方法です。 – Eugen