ズームのピンチジェスチャーに問題があります。主な問題は、ズームするとビューの中心がズームされるため、右上または下をピンチすると、ズームは常にビューの中心になります。これは私のコードですが、ピンチ タッチの途中でズームするように編集するにはどうすればよいですか?
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)gestureRecognizer{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
scala = [gestureRecognizer scale];
nextScala = [gestureRecognizer scale];
//NSLog(@"Scala: %f Gesture Scala %f",scala,[gestureRecognizer scale]);
}
else if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {
//CGPoint pointUno = [gestureRecognizer locationOfTouch:0 inView:[gestureRecognizer view]];
//CGPoint pointDue = [gestureRecognizer locationOfTouch:1 inView:[gestureRecognizer view]];
CGPoint point = [gestureRecognizer locationInView:[gestureRecognizer view]];
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
double minX = plotSpace.xRange.minLimitDouble;
double maxX = plotSpace.xRange.maxLimitDouble;
double minY = plotSpace.yRange.minLimitDouble;
double maxY = plotSpace.yRange.maxLimitDouble;
//NSLog(@"Scala: %f Gesture Scala %f Velocity: %f",scala,[gestureRecognizer scale],[gestureRecognizer velocity]);
double lenghtX = maxX - minX;
double lenghtY = maxY - minY;
float stepScale = lenghtX/25;
if ([gestureRecognizer scale] < nextScala) {
minX = plotSpace.xRange.minLimitDouble - stepScale;
maxX = plotSpace.xRange.maxLimitDouble + stepScale;
minY = plotSpace.yRange.minLimitDouble - stepScale;
maxY = plotSpace.yRange.maxLimitDouble + stepScale;
}
else {
minX = plotSpace.xRange.minLimitDouble + stepScale;
maxX = plotSpace.xRange.maxLimitDouble - stepScale;
minY = plotSpace.yRange.minLimitDouble + stepScale;
maxY = plotSpace.yRange.maxLimitDouble - stepScale;
}
lenghtX = maxX - minX;
lenghtY = maxY - minY;
NSLog(@"Old X: %f Y: %f",point.x,point.y);
NSLog(@"New X: %f Y: %f",lenghtX-point.x,lenghtY-point.y);
if (lenghtX > 0.05 && lenghtX < 4500) {
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(minX) length:CPTDecimalFromFloat(lenghtX)];
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(minY) length:CPTDecimalFromFloat(lenghtY)];
nextScala = [gestureRecognizer scale];
}
}
else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
[self performSelectorInBackground:@selector(getValues) withObject:nil];
// [自己 getValues]; } }