Вопрос

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;
        }
Это было полезно?

Решение 2

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.

Другие советы

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.

Not sure if there are any gremlins in your code without seeing more of it but there are two good previous Q&As regarding this issue.

The first Q&A deals with simply setting an anchor point. I tried this myself and it works fine.

The second Q&A goes into more detail about anchor points and their relationship to how the view is situated accordingly. The examples here also deal with setting anchor points.

There is also a sample project using anchor points on Github here.

I suggest you take a look at the two Q&As, the sample project project and compare them all against your code. Perhaps something will jump out at you which is causing your issue.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top