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;
}
This happens because as soon as you change the anchorpoint of the layer, you will also change the centerpoint of the layer's view. Let's say the view's frame is 0,0,100,100 then per default the view's center is at 50,50 because the anchorpoint is set to 0.5,0.5. When you now change the the anchorpoint to 0,0.5 the view's center is now at 0,50 causing it to jump when it gets drawn the next time. To avoid this you have to update the view's center after you changed the anchorpoint. I've tested it within the GMGridView
you described:
case UIGestureRecognizerStateBegan:
{
[self transformingGestureDidBeginWithGesture:pinchGesture];
_transformingItem.contentView.layer.anchorPoint = CGPointMake(0,0.5);
CGPoint orgCenter = _transformingItem.contentView.center;
orgCenter.x -= _transformingItem.contentView.frame.size.width / 2.f;
[_transformingItem.contentView setCenter:orgCenter];
}
break;
I hope this answers your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With