Resizing CAScrollLayer while maintaining current focus?

  • I have a CAScrollLayer that I am doing a scaling transform on, and I'd
    like to maintain it's current focus, i.e., I'd like to be the center
    of it's focus to be maintained so whatever point that was in the
    center of the current focus stays the center of the current focus as
    the scroll layer scales.

    I'm using the following code:

    //Get the current anchor point and store it for restoring later
    CGPoint anchorPoint = scrollLayer.anchorPoint;
    //Adjust the anchor point
    scrollLayer.anchorPoint = CGPointMake(0.5,0.5);
    //Scale the layer
    scrollLayer.transform = CATransform3DMakeScale(newScale, newScale, 1.0);
    //Adjust the bounds so that it fills the parent layer
    scrollLayer.bounds =
    CGRectMake
    (scrollLayer
    .bounds.origin.x,scrollLayer.bounds.origin.y,self.bounds.size.width/
    newScale,self.bounds.size.height/newScale);
    //restore the anchor point
    scrollLayer.anchorPoint = anchorPoint;

    The code doesn't seem to work though, and scales as if the anchor
    point was set to the lower left (which is what I have it originally
    set to before this code runs). Has anyone else ran into this issue? I
    have some code to manually maintain the focus written for an OpenGL
    version of this program, but I'd rather use something cleaner and
    built into CoreAnimation.

    Thanks,
    Colin
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today