Mac Developer Library

Developer

AppKit Framework Reference NSDrawer Class Reference

Options
Deployment Target:

On This Page
Language:

NSDrawer

An NSDrawer object is a user interface element that contains and displays view objects including NSTextView, NSScrollView, NSBrowser, and other classes that inherit from NSView. A drawer is associated with a window, called its parent, and can appear only while its parent is visible onscreen. A drawer cannot be moved or ordered independently of a window, but is instead attached to one edge of its parent and moves along with it.

  • Creates a new drawer with the given size on the specified edge of the parent window.

    Declaration

    Swift

    init(contentSize contentSize: NSSize, preferredEdge edge: NSRectEdge)

    Objective-C

    - (instancetype)initWithContentSize:(NSSize)contentSize preferredEdge:(NSRectEdge)edge

    Parameters

    contentSize

    The size of the new drawer.

    edge

    The edge to which to attach the new drawer.

    Discussion

    You must specify the parent window and content view of the drawer using the methods in this class. When you create a drawer in Interface Builder, this constructor is invoked. The NSDrawer Inspector in Interface Builder allows you to set the edge, and you can specify the size by changing the content view in Interface Builder.

    See Positioning and Sizing a Drawer for additional detail on content size and drawer positioning.

    Availability

    Available in OS X v10.0 and later.

  • The receiver’s delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSDrawerDelegate?

    Objective-C

    @property(assign) id< NSDrawerDelegate > delegate

    Discussion

    You may find it useful to associate a delegate with a drawer, especially since drawers do not open and close instantly. A drawer’s delegate can better regulate drawer behavior.

    Availability

    Available in OS X v10.0 and later.

  • If the receiver is open, this method closes it.

    Declaration

    Swift

    func close()

    Objective-C

    - (void)close

    Discussion

    Calling close on a closed drawer does nothing. You can get the state of a drawer by sending it state.

    Availability

    Available in OS X v10.0 and later.

    See Also

    – open

  • An action method to close the receiver.

    Declaration

    Swift

    func close(_ sender: AnyObject?)

    Objective-C

    - (void)close:(id)sender

    Parameters

    sender

    A user interface element, such as a button or menu item, that invokes the action method.

    Discussion

    This method is an action method and likely would not be invoked programatically. Rather, it is an action that is commonly connected in Interface Builder.

    Availability

    Available in OS X v10.0 and later.

    See Also

    – open:

  • If the receiver is closed, this method opens it.

    Declaration

    Swift

    func open()

    Objective-C

    - (void)open

    Discussion

    Calling open on an open drawer does nothing. You can get the state of a drawer by sending it state. If an edge is not specified, an attempt will be made to choose an edge based on the space available to display the drawer onscreen. If you need to ensure that a drawer opens on a particular edge, use openOnEdge:.

    Availability

    Available in OS X v10.0 and later.

    See Also

    – close

  • An action method to open the drawer.

    Declaration

    Swift

    func open(_ sender: AnyObject?)

    Objective-C

    - (void)open:(id)sender

    Parameters

    sender

    A user interface element, such as a button or menu item, that invokes the action method.

    Discussion

    This method is an action method and likely would not be invoked programatically. Rather, it is an action that is commonly connected in Interface Builder.

    Availability

    Available in OS X v10.0 and later.

    See Also

    – close:

  • Causes the receiver to open on the specified edge of the parent window.

    Declaration

    Swift

    func openOnEdge(_ edge: NSRectEdge)

    Objective-C

    - (void)openOnEdge:(NSRectEdge)edge

    Parameters

    edge

    The edge of the parent window on which to open the receiver. See Constants for a list of edge constants and locations.

    Availability

    Available in OS X v10.0 and later.

  • Toggles the drawer open or closed.

    Declaration

    Swift

    func toggle(_ sender: AnyObject?)

    Objective-C

    - (void)toggle:(id)sender

    Parameters

    sender

    The sender of the message.

    Discussion

    If the receiver is closed, or in the process of either opening or closing, it is opened. Otherwise, the drawer is closed.

    Availability

    Available in OS X v10.0 and later.

  • The state of the receiver. (read-only)

    Declaration

    Swift

    var state: Int { get }

    Objective-C

    @property(readonly) NSInteger state

    Availability

    Available in OS X v10.0 and later.

  • edge edge Property

    The edge of the window that the receiver is connected to. (read-only)

    Declaration

    Swift

    var edge: NSRectEdge { get }

    Objective-C

    @property(readonly) NSRectEdge edge

    Availability

    Available in OS X v10.0 and later.

  • The receiver’s preferred, or default, edge.

    Declaration

    Swift

    var preferredEdge: NSRectEdge

    Objective-C

    @property NSRectEdge preferredEdge

    Availability

    Available in OS X v10.0 and later.

  • The receiver’s content view.

    Declaration

    Swift

    var contentView: NSView?

    Objective-C

    @property(strong) NSView *contentView

    Availability

    Available in OS X v10.0 and later.

  • The receiver’s parent window.

    Declaration

    Swift

    unowned(unsafe) var parentWindow: NSWindow?

    Objective-C

    @property(assign) NSWindow *parentWindow

    Discussion

    Changes in a drawer’s parent window do not take place while the drawer is onscreen; they are delayed until the drawer next closes.

    Availability

    Available in OS X v10.0 and later.

Data Types

  • These constants specify the possible states of a drawer.

    Declaration

    Swift

    enum NSDrawerState : UInt { case ClosedState case OpeningState case OpenState case ClosingState }

    Objective-C

    typedef enum _NSDrawerState { NSDrawerClosedState = 0, NSDrawerOpeningState = 1, NSDrawerOpenState = 2, NSDrawerClosingState = 3 } NSDrawerState;

    Constants

    • ClosedState

      NSDrawerClosedState

      The drawer is closed (not visible onscreen).

      Available in OS X v10.0 and later.

    • OpeningState

      NSDrawerOpeningState

      The drawer is in the process of opening.

      Available in OS X v10.0 and later.

    • OpenState

      NSDrawerOpenState

      The drawer is open (visible onscreen).

      Available in OS X v10.0 and later.

    • ClosingState

      NSDrawerClosingState

      The drawer is in the process of closing.

      Available in OS X v10.0 and later.

    Discussion

    These constants are returned by state.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted whenever the drawer is closed.

    The notification object is the NSDrawer object that closed. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let NSDrawerDidCloseNotification: String

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted whenever the drawer is opened.

    The notification object is the NSDrawer object that opened. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let NSDrawerDidOpenNotification: String

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted whenever the drawer is about to close.

    The notification object is the NSDrawerobject about to close. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let NSDrawerWillCloseNotification: String

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted whenever the drawer is about to open.

    The notification object is the NSDrawer object about to open. This notification does not contain a userInfo dictionary.

    Declaration

    Swift

    let NSDrawerWillOpenNotification: String

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.