UIPinchGestureRecognizer を使用して X 座標と Y 座標の変化を計算し、プロット範囲を変更する方向 (X または Y) を決定しています。問題なく動いていますが、通常のズームほど滑らかではなく、反応が遅いです。誰かがこれを行うためのより良い方法を提案できますか
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer{
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan){
CGPoint translation = [gestureRecognizer locationInView:hostView];
NSLog(@"Sender value %f %f", translation.x,translation.y );
initialX = translation.x;
initialY = translation.y;
return;
}
else if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged){
NSLog(@"inside else");
CGPoint currentTouchLocation = [gestureRecognizer locationInView:hostView];
NSLog(@"currentTouchLocation = %f and %f and ",currentTouchLocation.x, currentTouchLocation.y);
finalX = currentTouchLocation.x;
finalY = currentTouchLocation.y;
}
}
-(CPTPlotRange *)plotSpace:(CPTPlotSpace *)space willChangePlotRangeTo:(CPTPlotRange *)newRange forCoordinate:(CPTCoordinate)coordinate
{
float x = fabsf(finalX - initialX) ;
float y = fabsf(finalY - initialY);
NSLog(@"pinch x = %f pinch y = %f", x, y);
CPTPlotRange *updatedRange = nil;
if (x > y) {
switch ( coordinate ) {
case CPTCoordinateX:
NSLog(@"x is greater than y change x-range");
if (newRange.locationDouble < 0.0F ) {
CPTMutablePlotRange *mutableRange = [[newRange mutableCopy] autorelease];
mutableRange.location = CPTDecimalFromFloat(0.0);
updatedRange = mutableRange;
}
else {
updatedRange = newRange;
}
break;
case CPTCoordinateY:
NSLog(@"x is greater than y keep y range constant");
updatedRange = ((CPTXYPlotSpace *)space).yRange;
break;
}
}
if (x < y) {
switch ( coordinate ) {
case CPTCoordinateX:
NSLog(@"y is greater than x keep x-range constant");
updatedRange = ((CPTXYPlotSpace *)space).xRange;
break;
case CPTCoordinateY:
if (newRange.locationDouble < 0.0F) {
NSLog(@"y is greater than x increase y range");
CPTMutablePlotRange *mutableRange = [[newRange mutableCopy] autorelease];
// mutableRange.location = CPTDecimalFromFloat(0.0);
updatedRange = mutableRange;
}
else {
updatedRange = newRange;
}
break;
}
}
if (x == y) {
switch ( coordinate ) {
case CPTCoordinateX:
NSLog(@"y is equal to x keep x-range constant");
updatedRange = ((CPTXYPlotSpace *)space).xRange;
break;
case CPTCoordinateY:
NSLog(@"y is equal to x keep y-range constant");
//NSLog(@"%d", CPTCoordinateY);
updatedRange = ((CPTXYPlotSpace *)space).yRange;
break;
}
}
return updatedRange;
}