I am trying to enlarge a drawing to a context based on infringement. This works fine, but will always increase from the beginning (top left). This does not give the pleasant effect that you get in other applications and is really annoying. The old scaling method is as follows:
- (IBAction)handlePinchGesture:(UIGestureRecognizer *)sender { UIPinchGestureRecognizer *pinch = (UIPinchGestureRecognizer *)sender; if ([pinch scale] > zoomLevel + MAX_ZOOM_PER_CALL) { [pinch setScale: zoomLevel + MAX_ZOOM_PER_CALL]; } if ([pinch scale] < zoomLevel - MAX_ZOOM_PER_CALL) { [pinch setScale:zoomLevel - MAX_ZOOM_PER_CALL]; } float prevZoomLevel = zoomLevel; CGFloat factor = [pinch scale]; zoomLevel = factor; if (zoomLevel < MIN_ZOOM_LEVEL) { zoomLevel = MIN_ZOOM_LEVEL; } if (zoomLevel > MAX_ZOOM_LEVEL) { zoomLevel = MAX_ZOOM_LEVEL; }
Actual scaling is done in the methods of drawing the parts that are shown in context. I was thinking about changing the origin of the screen (i.e. the relative origin of the objects that need to be drawn) so that it mimics this. But it does not work at all, this is what I have right now:
float dZoomLevel = zoomLevel - prevZoomLevel; if (dZoomLevel != 0) { CGPoint touchLocation = [pinch locationInView:self]; CGPoint zoomedTouchLocation = CGPointMake(touchLocation.x * prevZoomLevel, touchLocation.y * prevZoomLevel); CGPoint newLocation = CGPointMake(touchLocation.x * zoomLevel, touchLocation.y * zoomLevel); float dX = ( newLocation.x - zoomedTouchLocation.x ); float dY = ( newLocation.y - zoomedTouchLocation.y ); _originX += roundf(dX); _originY += roundf(dY); }
The origin is taken from xml (the smallest x and y of all elements). Usually it will be between 12000 and 20000, but theoretically it can be between 0 and 100000.
I'm not sure if I am clear, but if you need any information or I donβt understand something, just ask me and I will try to answer as soon as possible. Thanks in advance!
source share