How can I disable Cocoa's default animation wh

2020-07-18 02:32发布

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.

3条回答
叛逆
2楼-- · 2020-07-18 02:49

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];
查看更多
时光不老,我们不散
3楼-- · 2020-07-18 02:57

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).

查看更多
Melony?
4楼-- · 2020-07-18 03:00

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.

查看更多
登录 后发表回答