Search code examples
iphoneiosuigesturerecognizeruipinchgesturerecognizergmgridview

how to set anchor point of view for pinch zoom (GMGridView)


I am doing research on "Solar" app for learning purpose. I noticed a tile can be zoomed using pinch gesture. The way it was zooming clearly showed that had set anchor point of uiview.

you may see its video here http://www.youtube.com/watch?v=FfgWkAuLvng

To achieve the same, I downloaded GMGridView code. I tried to set the anchor point to get the same output as was in Solar app.

The problem i am facing is, On first time pinch zoom I can't get it zoomed at anchor point, but rest of the times. I couldn't find why its not zooming from anchor point for first time. Please help me.

I modified following method as

- (void)pinchGestureUpdated:(UIPinchGestureRecognizer *)pinchGesture

I modified the begin state of gesture recognizer as

 case UIGestureRecognizerStateBegan:
        {
            [self transformingGestureDidBeginWithGesture:pinchGesture];
            _transformingItem.contentView.layer.anchorPoint = CGPointMake(0,0.5);
            break;
        }

Solution

  • Please test following code taken from here. To understand more for anchorpoint please check this as well

    CGRect oldFrame = _transformingItem.contentView.frame;
    _transformingItem.contentView.layer.anchorPoint = CGPointMake(0, 0);
    _transformingItem.contentView.frame = oldFrame;
    

    Hope this helps, Let me know if you need more help.