Contents

CGDisplayFade(_:_:_:_:_:_:_:_:)

Performs a single fade operation.

Declaration

func CGDisplayFade(_ token: CGDisplayFadeReservationToken, _ duration: CGDisplayFadeInterval, _ startBlend: CGDisplayBlendFraction, _ endBlend: CGDisplayBlendFraction, _ redBlend: Float, _ greenBlend: Float, _ blueBlend: Float, _ synchronous: boolean_t) -> CGError

Parameters

  • token:

    A reservation token for the fade hardware you acquire by calling Cgacquiredisplayfadereservation(_:_:).

  • duration:

    The desired number of seconds for the fade operation. You should use a value in the interval [0, kCGMaxDisplayReservationInterval]. If the value is 0, Quartz applies the ending blend color immediately.

  • startBlend:

    An intensity value in the interval [0, 1] that specifies the alpha component of the desired blend color at the beginning of the fade operation. For more information, see Display Fade Blend Fractions.

  • endBlend:

    An intensity value in the interval [0, 1] that specifies the alpha component of the desired blend color at the end of the fade operation. For more information, see Display Fade Blend Fractions.

  • redBlend:

    An intensity value in the interval [0, 1] that specifies the red component of the desired blend color.

  • greenBlend:

    An intensity value in the interval [0, 1] that specifies the green component of the desired blend color.

  • blueBlend:

    An intensity value in the interval [0, 1] that specifies the blue component of the desired blend color.

  • synchronous:

    Pass true if you want the fade operation to be synchronous; otherwise, pass false. If a fade operation is synchronous, the function doesn’t return until the operation is complete.

Return Value

A result code. To interpret the result code, see CGError.

Discussion

Over the fade operation time interval, Quartz interpolates a blending coefficient between the starting and ending values given, applying a nonlinear (sine-based) bias term. Using this coefficient, Quartz blends the video output with the specified color.

The following example shows how to perform a 2-second synchronous fade-out to black:

CGDisplayFade (
    myToken,
    2.0,                        // 2 seconds
    kCGDisplayBlendNormal,      // starting state
    kCGDisplayBlendSolidColor,  // ending state
    0.0, 0.0, 0.0,              // black
    true                        // wait for completion
);

To perform a 2-second asynchronous fade-in from black:

CGDisplayFade (
    myToken,
    2.0,                        // 2 seconds
    kCGDisplayBlendSolidColor,  // starting state
    kCGDisplayBlendNormal,      // ending state
    0.0, 0.0, 0.0,              // black
    false                       // don't wait for completion
);

If you specify an asynchronous fade operation, it’s safe to call CGReleaseDisplayFadeReservation(_:) immediately after this function returns.

See Also

Functions