I am trying to replicate a screen flash effect in a mac cocoa application similar to that of the Photo Booth.
A white layer is overlayed on the screen and the brightness of the screen fades really bright and then d开发者_如何学Pythonown again.
Can anyone give me some advice on how this can be replicated in Cocoa?
Thanks
I suggest using the CGDisplayFade API of Quartz Display Services. It's very easy to use and no "hacking" with fake fullscreen windows or views is required.
See here: Quartz Display Services Reference
A simple implementation would look like this:
-(void)flashScreenUsingFlashColor:(NSColor *)flashColor
inDuration:(NSTimeInterval)inDuration
outDuration:(NSTimeInterval)outDuration{
CGDisplayFadeReservationToken fadeToken;
NSColor *colorToUse = [flashColor colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
CGError error = CGAcquireDisplayFadeReservation (inDuration + outDuration, &fadeToken);
if (error != kCGErrorSuccess){
NSLog(@"Error aquiring fade reservation. Will do nothing.");
return;
}
CGDisplayFade (fadeToken, inDuration, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, colorToUse.redComponent, colorToUse.greenComponent, colorToUse.blueComponent, true);
CGDisplayFade (fadeToken, outDuration, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal,colorToUse.redComponent, colorToUse.greenComponent, colorToUse.blueComponent, false);
}
You could take a look at this tutorial for creating a full screen window. Just make it white and the use Core Animation to fade it in and out. For example: [[MyFullScreenWindow animator] setAlphaValue:0.0];
will fade it out.
精彩评论