Mac Developer Library

Developer

ScreenSaver Framework Reference ScreenSaverView Class Reference

Options
Deployment Target:

On This Page
Language:

ScreenSaverView

ScreenSaverView is an abstract class that defines the interface for subclassers to interact with the screen saver infrastructure.

Screen savers are subclasses of ScreenSaverView, packaged up in bundles and loaded by the screen saver application. (These bundles have a suffix of .saver and are located in the Library/Screen Savers directories of the various file system domains. See File System Overview for information about domains.) ScreenSaverView defines an interface for animating screen savers, instantiating small preview versions of the screen saver view (for display in System Preferences, for example), and for providing a configuration sheet to set various properties of the screen saver. In addition, subclasses can set the animation interval, the backing store of their window, and how the screen transitions to the animation.

There are two main ways to do drawing in a screen saver. You can either do your drawing in the NSView method drawRect:, or you can do your drawing in the ScreenSaverView method animateOneFrame. If you do drawing in drawRect:, you should call setNeedsDisplay: with an argument of YEStrue in animateOneFrame.

Inheritance


Import Statement


Swift

import ScreenSaver

Objective-C

@import ScreenSaver;

Availability


Available in OS X v10.0 and later.
  • Calls initWithFrame:isPreview: with an argument of NOfalse.

    Declaration

    Swift

    init!(frame frame: NSRect)

    Objective-C

    - (id)initWithFrame:(NSRect)frame

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Initializes a newly allocated ScreenSaverView with frame as its frame rectangle, and sets the value returned by isPreview to isPreview.

    Declaration

    Swift

    init!(frame frame: NSRect, isPreview isPreview: Bool)

    Objective-C

    - (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview

    Discussion

    The screen saver application will install the new view object into the view hierarchy of an NSWindow before the animation begins. This method is the designated initializer for the ScreenSaverView class. Returns self.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Returns the desired backing store for windows in which the screen saver view will be instantiated.

    Declaration

    Swift

    class func backingStoreType() -> NSBackingStoreType

    Objective-C

    + (NSBackingStoreType)backingStoreType

    Discussion

    Subclasses should override this method to return the desired backing store. The default is NSBackingStoreBuffered.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Indicates whether the screen saver application should perform a gradual screen fade when it starts and stops the animation.

    Declaration

    Swift

    class func performGammaFade() -> Bool

    Objective-C

    + (BOOL)performGammaFade

    Discussion

    This class method allows the screen saver view to select how the desktop visibly transitions to the screen saver view. If this method returns YEStrue, the screen will gradually darken before the animation begins. If it returns NOfalse, the transition will be immediate. The latter behavior is more appropriate if the screen saver animates a screen shot of the desktop, as is the case for optical lens effects. The default is YEStrue.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Activates the periodic timer that animates the screen saver.

    Declaration

    Swift

    func startAnimation()

    Objective-C

    - (void)startAnimation

    Discussion

    This method is called when the screen saver view should begin animating. Subclasses can implement this method to set up initial state or allocate expensive resources that should be loaded lazily. Subclasses must call the inherited implementation.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Advances the screen saver’s animation by a single frame.

    Declaration

    Swift

    func animateOneFrame()

    Objective-C

    - (void)animateOneFrame

    Discussion

    This method is called each time the timer animating the screen saver fires. The time between calls to this method is always at least animationTimeInterval. It is guaranteed that the focus is locked when this method is called, so subclasses may do drawing in this method. The subclass can also let drawRect: perform the drawing, in which case animateOneFrame needs to call setNeedsDisplay: with an argument of YEStrue. The default implementation does nothing.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

    See Also

    – drawRect:

  • Deactivates the timer that advances the animation.

    Declaration

    Swift

    func stopAnimation()

    Objective-C

    - (void)stopAnimation

    Discussion

    This method is called when the screen saver view should stop animating. Subclasses can implement this method to unload expensive resources or reset state to original parameters. Subclasses must call the inherited implementation.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Returns YEStrue if the screen saver is currently animating, NOfalse otherwise.

    Declaration

    Swift

    func isAnimating() -> Bool

    Objective-C

    - (BOOL)isAnimating

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Draws the screen saver view.

    Declaration

    Swift

    func drawRect(_ rect: NSRect)

    Objective-C

    - (void)drawRect:(NSRect)rect

    Discussion

    ScreenSaverView implements drawRect: to draw a black background. Subclasses can do their drawing here or in animateOneFrame.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Returns YEStrue if the screen saver view was created in a smaller size to be used as a preview, NOfalse if it was created full-screen for use as a screen saver.

    Declaration

    Swift

    func isPreview() -> Bool

    Objective-C

    - (BOOL)isPreview

    Discussion

    Subclasses can use the return value of isPreview to determine if they should change their drawing parameters to something more suitable for display in a smaller frame.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Returns whether the screen saver has an associated configuration sheet.

    Declaration

    Swift

    func hasConfigureSheet() -> Bool

    Objective-C

    - (BOOL)hasConfigureSheet

    Discussion

    Subclasses that provide configure sheets as part of their bundle should override this method to return YEStrue.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.

  • Returns the window containing all of the controls to be used for configuring the screen saver.

    Declaration

    Swift

    func configureSheet() -> NSWindow!

    Objective-C

    - (NSWindow *)configureSheet

    Discussion

    This window will be run as a sheet, so it must include buttons that allow the user to end the modal session in which the sheet runs. When the user dismisses the sheet, the controller in charge of the sheet must end the document modal session by calling the NSApplication method endSheet: with the sheet’s window as the argument.

    Import Statement

    Objective-C

    @import ScreenSaver;

    Swift

    import ScreenSaver

    Availability

    Available in OS X v10.0 and later.