I had considered doing this with Core Animation, but it just seems simpler to get this working. Here is the code that I'm using (adapted from Hillegass, Chapter 29):

-(void)displayViewController:(NSViewController *)vc
{
        NSWindow *w = [self window];
        NSView *v = [vc view];
        
        // Compute the new window frame
        NSSize currentSize = [[w contentView] frame].size;
        NSSize newSize = [v frame].size;
        float deltaWidth = newSize.width - currentSize.width;
        float deltaHeight = newSize.height - currentSize.height;
        NSRect windowFrame = [w frame];
        windowFrame.size.height += deltaHeight;
        windowFrame.origin.y -= deltaHeight;
        windowFrame.size.width += deltaWidth;
        
        [w setContentView:nil];
        [w setFrame:windowFrame display:YES animate:YES];
        [w setContentView:v];
}

This works as expected (except for flickering). That is, the window resizes to fit views of different sizes. I found I can actually stop the flickering if I comment out the [w setContentView:nil]; line, except then the window resizing gets all messed up. To tell you the truth, I'm not sure why [w setContentView:nil]; makes such a difference, to the flickering or to the resizing.

On 21-Feb-09, at 3:14 AM, Mike Abdullah wrote:

Did you need to target anything pre-Leopard? If not, I'd recommend using Core Animation instead of this method. It'll have the advantage of being GPU-powered and more importantly won't block the main thread during the animation (I frequently try to move the System Prefs somewhere more convenient while a pane is loading, and it annoyingly snaps back into place).

Mike.

On 21 Feb 2009, at 02:31, K. Darcy Otto wrote:

I have a window, and get that window to resize according to the various custom views I plop in the window. My purpose here is to (somewhat) emulate the system preferences window that grows and shrinks as necessary. The resizing works fine, but when I want to animate the resizing, there is a lot of flickering in the window. Here is the short bit of code:

[w setContentView:nil];
[w setFrame:windowFrame display:YES animate:YES];
[w setContentView:v];

... where "w" is an NSWindow, and "v" is an NSView. "windowFrame" is the recalculated window size that fits the view. So far, I have tried to solve the flickering by subclassing NSWindow and implementing the following override:

- (NSTimeInterval)animationResizeTime:(NSRect)newFrame
{
  return 1.0;
}

But while this does slow down the animation significantly, it simply makes the flickering slower.

Is there a way to use setFrame:display:animate: so that the background of the window does not flicker?

Thanks.
_______________________________________________

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/cocoadev%40mikeabdullah.net

This email sent to cocoa...@mikeabdullah.net


_______________________________________________

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