Animate magnifyToFitRect:

  • Hi,
    in my custom NSClipView class I would like to subclass the method
    smartMagnifyWithEvent and zoom the rect on which the user has double tapped.
    So I properly detect the rect to magnify, then I tell the scrollView to

    [self.superview magnifyToFitRect:boxFrame];

    and I properly get the view zoomed to the tapped area. It works.
    Now I would like to animate the zoom, and as I have read on the
    NSScrollView.h document, I could animate the magnifyToFitRect API using use
    the object's animator.
    I tried to use my traditional way (which usualy works well), unsuccessfully:

    [NSAnimationContext beginGrouping];
    [[NSAnimationContext currentContext] setDuration:1.0];
    [[NSAnimationContext currentContext] setCompletionHandler:^{
        [self animationDidStop];

    [[self.superview animator] magnifyToFitRect:boxFrame];
    [NSAnimationContext endGrouping];

    I get the zoom without any animation. I even tried to call

    [self setWantsLayer:YES];

    within the init method. Then I got something moving, but the content of the
    view is a mess.
    The nested objects are placed here and there without a reason. Also the
    document view loses its dimensions.
    How can I achieve my target?

    -- Leonardo
previous month april 2013 next month
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          
Go to today