Set animation Time for a Window

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

But I can’t find a way to use it.

Thanks for your help.

You need to make your window a subclass of NSWindow, and override the method something like:

on animationResizeTime_(rect)
return 0.5 – or calculate a value based on the passed NSRect value
end animationResizeTime_

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.

Thanks for your help.

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.

Ric

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.

Anyway, thanks for your help.

Have a look at chapter 10 of my book – it gives an example of subclassing a class and overriding a method.

There’s no secret to reading the terminology, though: you really have to read the documentation and try to understand the sample code.

An AppleScript handler is is just the AppleScript equivalent of a method. Go and look at the example in chapter 10 again, and see if it’s any clearer.