Hi People,

I am learning how to use a little core animation to make my user interface look cooler, but I am stuck with the following problem:

I use a disclosure button do expand/contract a custom view which, in turn, is used to display an open bez-path. In the view's drawRect: I stroke the path with a 2 point line-width. The points are calculated based on the view's geometry so that it plots the curve over a wider area when the view is larger, but allways with the same line thickness.

I want to use the basic, built-in NSView core animation stuff to make the frame-change be smooth. That is all, and it works ok except that, since the image is cached, the once crisp 2.0 point line becomes a blurred thicker contour as the view expands. (note: drawing works perfectly without using the animator).

1) Animation code is bellow (VERSION A) -- Is there a way to make core animation query my view whenever the rect changes so that it can redraw itself correctly? (Obviously CA's caching is very useful and much more efficient, but in my case it produces undesired results...) Or am I doing it all wrong?

2) alternatively I tried recalling the rect change without the animator, after the animation grouping (VERSION B), so that, at least, after the animation I could have a correctly rendered view. Instead of that, it seemed to be doing the entire animation with the desired drawing, but produced a horrible glitch at the begining of the animation. I can't really live with this glitch (it is so ugly it defeats the purpose of using animation...),. It seems like the view flashes in the new size because of the second call to setFrame and then the animation kicks in assyncronously, resets the view size and starts expanding the view. Slowing down the animation, I can see there is an ilusion of the drawing being correct because the view is already set to the target size.

Hope this is not too confusing. I would really appreciate any suggetions on how to do this right.

Carlos.


// VERSION A =======================

- (IBAction)resizeMyView:(id)sender
{       
        switch([sender state])
        {
                case NSOffState:
                {
                        NSRect newFrame = NSMakeRect(20, 30, 760, 567);
                        
                        [NSAnimationContext beginGrouping];
                        [[NSAnimationContext currentContext] setDuration:0.5];
                        
                                [[myView animator] setFrame: newFrame];
                                [myView setNeedsDisplay:YES];
                        
                        [NSAnimationContext endGrouping];
                        
                        break;
                }
                        
                case NSOnState:
                {
                        NSRect oldFrame = NSMakeRect(20, 30, 760, 130);
                        
                        [NSAnimationContext beginGrouping];
                        [[NSAnimationContext currentContext] setDuration:0.5];
                        
                                [[myView animator] setFrame:oldFrame];
                                [myView setNeedsDisplay:YES];
                        
                        [NSAnimationContext endGrouping];
                        
                        break;
                }
        }
}

// VERSION B =======================

- (IBAction)resizeMyView:(id)sender
{       
        switch([sender state])
        {
                case NSOffState:
                {
                        NSRect newFrame = [self createRectWithX:20 y:30 w:760 
h:567];
                        
                        [NSAnimationContext beginGrouping];
                        [[NSAnimationContext currentContext] setDuration:0.5];
                                [[myView animator] setFrame:newFrame];
                                [myView setNeedsDisplay:YES];
                        [NSAnimationContext endGrouping];
                        
                        [myView setFrame:newFrame];
                        [myView setNeedsDisplay:YES];
                        
                        break;
                }
                        
                case NSOnState:
                {
                        NSRect oldFrame = [self createRectWithX:20 y:30 w:760 
h:130];
                        
                        [NSAnimationContext beginGrouping];
                        [[NSAnimationContext currentContext] setDuration:0.5];
                                [[myView animator] setFrame:oldFrame];
                                [myView setNeedsDisplay:YES];
                        [NSAnimationContext endGrouping];

                        [myView setFrame:oldFrame];
                        [myView setNeedsDisplay:YES];
                        
                        break;
                }
        }
}

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to