-->

How can I disable Cocoa's default animation wh

2020-07-18 02:02发布

问题:

I would like to disable the animation that Cocoa performs when displaying a modal sheet.

Apple's Sheet Programming Guide states:

... Other sheet behavior, such as the animation when it appears and is dismissed, is handled automatically by the Application Kit.

But it doesn't provide any hints on how to disable this effect.

I have created a custom sheet (a subclass of NSWindow with a transparent background and some controls in it). I am able to display it using the standard beginSheet method as follows:

[NSApp beginSheet:myCustomSheet
   modalForWindow:mainWindow
    modalDelegate:self
   didEndSelector:...];

The sheet displays fine, but it goes through an animation when it appears, and again when it closes.

Note: I am writing a completely customized user interface for a touch screen / kiosk type app, so none of the usual Apple user interface guidelines apply.

回答1:

This is a wild guess (I'm too lazy to try it) but the animation might be handled using Core Animation. If so, you might be able to do this:

[CATransaction begin];
[CATransaction setValue: [NSNumber numberWithBool: YES]
    forKey: kCATransactionDisableActions ];
[NSApp beginSheet:myCustomSheet
   modalForWindow:mainWindow
    modalDelegate:self
   didEndSelector:...];
[CATransaction commit];


回答2:

There is a user default for the animation speed of sheets. Look it up and see what happens if you try to set it to 0.



回答3:

Override animationResizeTime: in the NSWindow you're presenting as a sheet and have it return 0. This is better than messing with CATransaction (which doesn't seem to work reliably) or NSWindowResizeTime (which affects all windows).