Re: Window Animation with setFrame:display:animate: Flickers [solved]
Re: Window Animation with setFrame:display:animate: Flickers [solved]
- Subject: Re: Window Animation with setFrame:display:animate: Flickers [solved]
- From: "K. Darcy Otto" <email@hidden>
- Date: Wed, 25 Feb 2009 22:46:18 -0800
Thank you for the hints. I eventually solved this problem by setting
up a box that took up the whole window in IB, and setting the
autosizing so that it resized automatically with the window. I then
set the content view of the box with the view. The flickering has
stopped when the window is resized. Here is the code I used:
-(void)displayViewController:(NSViewController *)vc
{
NSWindow *w = [box window];
NSView *v = [vc view];
// Compute the new window frame
NSSize currentSize = [[box 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;
[box setContentView:nil];
[w setFrame:windowFrame display:YES animate:YES];
[box setContentView:v];
}
On 21-Feb-09, at 11:58 AM, Markus Spoettl wrote:
On Feb 21, 2009, at 8:03 PM, K. Darcy Otto wrote:
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];
}
You probably shouldn't replace the content view with your own view.
The content view is a container that is managed by the window
(resized to the window's specifications as the window resizes, for
example). Instead of replacing it you probably want to add your view
as a sub-view of the content view, something like this:
// todo: set this up to your liking
NSRect contentBounds = [[w contentView] bounds];
// fill content view entirely
[v setFrame:contentBounds];
// adjust width and height to content view/window
[v setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[[w contentView] addSubview:v];
[w setFrame:windowFrame display:YES animate:YES];
Warning, programmed in Mail.app
Markus
--
__________________________________________
Markus Spoettl
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden