Cocoa animated frame in preference window
Looking at many OSX application i oft开发者_如何转开发en see preference window frame grow up and down depending on view contents activated by toolbar buttons.
I'd like to know if there's a way to automatize frame size dimension or if the only way is to resize and animate it programmatically.
I think you can only use NSWindow's setFrame:display:animate: I don't think the windows can be sized automatically. So when you change the contents you can do something like this:
NSRect oldContentFrame = [oldContentView frame];
NSRect newContentFrame = [newContentView frame];
float widthDifference = oldContentFrame.size.width - newContentFrame.size.width;
float heightDifference = oldContentFrame.size.height - newContentFrame.size.height;
// Change the size of the window by the difference between the two views
// and move the frame up/down
NSRect windowFrame = [window frame];
windowFrame.size.width -= widthDifference;
windowFrame.size.height -= heightDifference;
windowFrame.origin.y += heightDifference;
// Remove the old content
[oldContentView removeFromSuperview];
// Change the size
[window setFrame:windowFrame display:YES animate:YES];
// Add the new view
[window setContentView:newContentView];
Have a look at DBPrefsWindowController
by Dave Batton. It allows you to do exactly what you want and almost all of the config is just done in Interface Builder.
Well You can use a library RHPreferencesWindowController. it is easy to use
RHPreferences
精彩评论