Mac Developer Library

Developer

AppKit Framework Reference NSDrawer Class Reference

Options
Deployment Target:

On This Page
Language:

NSDrawer

Inheritance


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.

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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSDrawerDelegate?

    Objective-C

    @property(assign) id<NSDrawerDelegate> delegate

    Return Value

    The receiver’s delegate.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSDrawerDelegate?

    Objective-C

    @property(assign) id<NSDrawerDelegate> delegate

    Parameters

    anObject

    The object to assign as the receiver’s delegate. The object must conform to the NSDrawerDelegate Protocol Reference.

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – delegate

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the state of the receiver.

    Declaration

    Swift

    var state: Int { get }

    Objective-C

    @property(readonly) NSInteger state

    Return Value

    The drawer's state. Refer to NSDrawerState for a list of possible values.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the size of the receiver’s content area.

    Declaration

    Swift

    var contentSize: NSSize

    Objective-C

    @property NSSize contentSize

    Return Value

    The size of the receiver’s content area.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s leading offset.

    Declaration

    Swift

    var leadingOffset: CGFloat

    Objective-C

    @property CGFloat leadingOffset

    Return Value

    The receiver’s leading offset. This is the distance from the top or left edge of the parent window to the drawer.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the maximum allowed size of the receiver’s content area.

    Declaration

    Swift

    var maxContentSize: NSSize

    Objective-C

    @property NSSize maxContentSize

    Return Value

    The maximum size of the receiver’s content area. This is useful for determining if an opened drawer would fit onscreen given the current window position.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the minimum allowed size of the receiver’s content area.

    Declaration

    Swift

    var minContentSize: NSSize

    Objective-C

    @property NSSize minContentSize

    Return Value

    The minimum size of the receiver’s content area.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the size of the receiver’s content area.

    Declaration

    Swift

    var contentSize: NSSize

    Objective-C

    @property NSSize contentSize

    Parameters

    size

    The new size of the receiver’s content area. See Positioning and Sizing a Drawer for additional detail.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s leading offset.

    Declaration

    Swift

    var leadingOffset: CGFloat

    Objective-C

    @property CGFloat leadingOffset

    Parameters

    offset

    The leading offset of the receiver. This is the distance from the top or left edge of the parent window to the drawer. See Positioning and Sizing a Drawer for additional detail.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Specifies the maximum size of the receiver’s content area.

    Declaration

    Swift

    var maxContentSize: NSSize

    Objective-C

    @property NSSize maxContentSize

    Parameters

    size

    The new maximum size of the receiver’s content area. See Positioning and Sizing a Drawer for additional detail.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Specifies the minimum size of the receiver’s content area.

    Declaration

    Swift

    var minContentSize: NSSize

    Objective-C

    @property NSSize minContentSize

    Parameters

    size

    The new minimum size of the receiver’s content area. See Positioning and Sizing a Drawer for additional detail.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s trailing offset.

    Declaration

    Swift

    var trailingOffset: CGFloat

    Objective-C

    @property CGFloat trailingOffset

    Parameters

    offset

    The receiver’s trailing offset. This is the distance to the right or bottom edge of the drawer from the right or bottom edge of the parent window. See Positioning and Sizing a Drawer for additional detail.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s trailing offset.

    Declaration

    Swift

    var trailingOffset: CGFloat

    Objective-C

    @property CGFloat trailingOffset

    Return Value

    The receiver’s trailing offset. This is the distance to the right or bottom edge of the drawer from the right or bottom edge of the parent window.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the edge of the window that the receiver is connected to.

    Declaration

    Swift

    var edge: NSRectEdge { get }

    Objective-C

    @property(readonly) NSRectEdge edge

    Return Value

    The edge of the parent window at which the drawer is attached. See Constants for a list of edge constants and locations.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s preferred, or default, edge.

    Declaration

    Swift

    var preferredEdge: NSRectEdge

    Objective-C

    @property NSRectEdge preferredEdge

    Return Value

    The receiver’s preferred edge. If a drawer is told to open and an edge is not specified at that time, it opens on its preferred edge. When you a create a drawer with Interface Builder, the preferred edge is set to the left by default.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s preferred, or default, edge.

    Declaration

    Swift

    var preferredEdge: NSRectEdge

    Objective-C

    @property NSRectEdge preferredEdge

    Parameters

    preferredEdge

    The edge on which the receiver should open by default. A drawer can be told to open on a specific edge; if an edge is not specified, however, it opens on the preferred edge.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s content view.

    Declaration

    Swift

    var contentView: NSView?

    Objective-C

    @property(strong) NSView *contentView

    Return Value

    The receiver’s content view.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the receiver’s parent window.

    Declaration

    Swift

    unowned(unsafe) var parentWindow: NSWindow?

    Objective-C

    @property(assign) NSWindow *parentWindow

    Return Value

    The receiver’s parent window. By definition, a drawer can appear onscreen only if it has a parent.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the receiver’s content view.

    Declaration

    Swift

    var contentView: NSView?

    Objective-C

    @property(strong) NSView *contentView

    Parameters

    aView

    The content view of the receiver. Rather than connect a drawer to its content view in Interface Builder, you can specify it programatically with this method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    See Also

    – contentView

  • Sets the receiver’s parent window.

    Declaration

    Swift

    unowned(unsafe) var parentWindow: NSWindow?

    Objective-C

    @property(assign) NSWindow *parentWindow

    Parameters

    parent

    The parent window of the receiver. Every drawer must be associated with a parent window for a drawer to appear onscreen. If this argument is nil, the drawer is removed from its parent.

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    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.

    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.

    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.

    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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.