Hi,
I would like to control the speed of a animated window.
Using the “setFrame_display_animate_” to resize a window, I’ve notice that there is a instance of the NSWindow that allow this:
(NSTimeInterval)animationResizeTime:(NSRect)newWindowFrame
Hi Shane,
Thanks for your answer.
Would you mind show me how this subclassing and overriding mechanism works in a complete code like the one you provided in the chapter 11 of your book (the part where you resize the window)? So I’ll be more familiar with the subclassing technique.
To subclass, you just need to add a new file, and set it’s parent class to NSWindow. In IB you set the class of your window to this new class (its name should show up in the pull down list next to Class in the identity inspector). Then you just need to to override the one method, animationResizeTime_ like this:
script WindowTimer
property parent : class "NSWindow"
on animationResizeTime_(rect)
return 2
end
end script
I used the setFrame_display_animate_ method like this, called from a button in the window:
on buttonClick_(sender)
set {origin:{x:xp, y:yp}, |size|:{height:h, |width|:w}} to win's frame()
win's setFrame_display_animate_({{xp,yp},{600,450}},1,1)
end
I started with a window that was set to w=200, h=150 in IB. You also need to deselect the Restorable check box in the attributes inspector, or the window will come up with its new size the second time you run the app.
Rdelmar and Shane, thanks for your answer, it works great.
Where can I find this kind of very basic information (how to subclass, how to override, how to read the Cocoa’s terminology)?
For instance the Cocoa documentation for “animationResizeTime” is written like that : (NSTimeInterval)animationResizeTime:(NSRect)
How could I knew that (NSTimeInterval) could be set in a AppleScript “handler”?
Shane’s book is a mining gold (and I’m very grateful of him) but it sometimes lack of very basic answer like this one.