Class

NSView

The infrastructure for drawing, printing, and handling events in an app.

Overview

You typically don’t use NSView objects directly. Instead, you use objects whose classes descend from NSView or you subclass NSView yourself and override its methods to implement the behavior you need. An instance of the NSView class (or one of its subclasses) is commonly known as a view object, or simply as a view.

Views handle the presentation and interaction with your app’s visible content. You arrange one or more views inside an NSWindow object, which acts as a wrapper for your content. A view object defines a rectangular region for drawing and receiving mouse events. Views handle other chores as well, including the dragging of icons and working with the NSScrollView class to support efficient scrolling.

Most of the functionality of the NSView class is automatically invoked by AppKit. Unless you’re implementing a concrete subclass of NSView or working intimately with the content of the view hierarchy at runtime, you don’t need to know much about this class’s interface. For any view, there are many methods that you can use as-is. The following methods are commonly used.

  • frame returns the location and size of the NSView object.

  • bounds returns the internal origin and size of the NSView object.

  • needsDisplay determines whether the NSView object needs to be redrawn.

  • window returns the NSWindow object that contains the NSView object.

  • drawRect: draws the NSView object. (All subclasses must implement this method, but it’s rarely invoked explicitly.)

For more information on how NSView instances handle event and action messages, see Cocoa Event Handling Guide. For more information on displaying tooltips and contextual menus, see Displaying Contextual Menus and Managing Tooltips.

Subclassing Notes

NSView is perhaps the most important class in AppKit when it comes to subclassing and inheritance. Most user-interface objects you see in a Cocoa application are objects that inherit from NSView. If you want to create an object that draws itself in a special way, or that responds to mouse clicks in a special way, you would create a custom subclass of NSView (or of a class that inherits from NSView). Subclassing NSView is such a common and important procedure that several technical documents describe how to both draw in custom subclasses and respond to events in custom subclasses. See Cocoa Drawing Guide and Cocoa Event Handling Guide (especially "Handling Mouse Events" and "Mouse Events").

Handling Events in Your Subclass

If you subclass NSView directly and handle specific types of events, the implementation of your event-related methods should generally not call super. Views inherit their event-handling capabilities from their NSResponder parent class. The default behavior for responders is to pass events up the responder chain, which is not the behavior you typically want if you handle events in a custom view. Therefore, you should not call super if your view implements any of the following methods and handles the event:

If your view descends from a class other than NSView, call super to let the parent view handle any events that you do not.

Topics

Creating Instances

initWithFrame:

Initializes and returns a newly allocated NSView object with a specified frame rectangle.

prepareForReuse

Restores the view to an initial state so that it can be reused.

Managing the View Hierarchy

superview

The view that is the parent of the current view.

subviews

The array of views embedded in the current view.

window

The view’s window object, if it is installed in a window.

addSubview:

Adds a view to the view’s subviews so it’s displayed above its siblings.

addSubview:positioned:relativeTo:

Inserts a view among the view’s subviews so it’s displayed immediately above or below another view.

didAddSubview:

Overridden by subclasses to perform additional actions when subviews are added to the view.

removeFromSuperview

Unlinks the view from its superview and its window, removes it from the responder chain, and invalidates its cursor rectangles.

removeFromSuperviewWithoutNeedingDisplay

Unlinks the view from its superview and its window and removes it from the responder chain, but does not invalidate its cursor rectangles to cause redrawing.

replaceSubview:with:

Replaces one of the view’s subviews with another view.

isDescendantOf:

Returns YES if the view is a subview of a given view or if it’s identical to that view; otherwise, it returns NO.

opaqueAncestor

The view’s closest opaque ancestor, which might be the view itself.

ancestorSharedWithView:

Returns the closest ancestor shared by the view and another specified view.

sortSubviewsUsingFunction:context:

Orders the view's immediate subviews using the specified comparator function.

viewDidMoveToSuperview

Informs the view that its superview has changed (possibly to nil).

viewDidMoveToWindow

Informs the view that it has been added to a new view hierarchy.

viewWillMoveToSuperview:

Informs the view that its superview is about to change to the specified superview (which may be nil).

viewWillMoveToWindow:

Informs the view that it’s being added to the view hierarchy of the specified window object (which may be nil).

willRemoveSubview:

Overridden by subclasses to perform additional actions before subviews are removed from the view.

enclosingMenuItem

The menu item containing the view or any of its superviews in the view hierarchy.

Modifying the Frame Rectangle

frame

The view’s frame rectangle, which defines its position and size in its superview’s coordinate system.

setFrameOrigin:

Sets the origin of the view’s frame rectangle to the specified point, effectively repositioning it within its superview.

setFrameSize:

Sets the size of the view’s frame rectangle to the specified dimensions, resizing it within its superview without affecting its coordinate system.

frameRotation

The angle of rotation, measured in degrees, applied to the view’s frame rectangle relative to its superview’s coordinate system.

Modifying the Bounds Rectangle

bounds

The view’s bounds rectangle, which expresses its location and size in its own coordinate system.

setBoundsOrigin:

Sets the origin of the view’s bounds rectangle to a specified point.

setBoundsSize:

Sets the size of the view’s bounds rectangle to specified dimensions, inversely scaling its coordinate system relative to its frame rectangle.

boundsRotation

The angle of rotation, measured in degrees, applied to the view’s bounds rectangle relative to its frame rectangle.

Managing the View’s Layer

wantsLayer

A Boolean value indicating whether the view uses a layer as its backing store.

wantsUpdateLayer

A Boolean value indicating which drawing path the view takes when updating its contents.

layer

The Core Animation layer that the view uses as its backing store.

makeBackingLayer

Creates the view’s backing layer.

layerContentsPlacement

The current layer contents placement policy.

layerContentsRedrawPolicy

The contents redraw policy for the view’s layer.

canDrawSubviewsIntoLayer

A Boolean value indicating whether the view incorporates content from its subviews into its own layer.

layerUsesCoreImageFilters

A Boolean value indicating whether the view’s layer uses Core Image filters and needs in-process rendering.

Managing Layer-Related Properties

alphaValue

The opacity of the view.

frameCenterRotation

The rotation angle of the view around the center of its layer.

backgroundFilters

An array of Core Image filters to apply to the view’s background.

compositingFilter

The Core Image filter used to composite the view’s contents with its background.

contentFilters

An array of Core Image filters to apply to the contents of the view and its sublayers.

shadow

The shadow displayed underneath the view.

Drawing

updateLayer

Updates the view’s content by modifying its underlying layer.

drawRect:

Overridden by subclasses to draw the view’s image within the specified rectangle.

canDraw

A Boolean value indicating whether drawing commands will produce any results.

canDrawConcurrently

A Boolean value indicating whether the view can draw its contents on a background thread.

visibleRect

The portion of the view that is not clipped by its superviews.

getRectsBeingDrawn:count:

Returns by indirection a list of nonoverlapping rectangles that define the area the view is being asked to draw in drawRect:.

needsToDrawRect:

Returns a Boolean value indicating whether the specified rectangle intersects any part of the area that the view is being asked to draw.

wantsDefaultClipping

A Boolean value indicating whether AppKit’s default clipping behavior is in effect.

bitmapImageRepForCachingDisplayInRect:

Returns a bitmap-representation object suitable for caching the specified portion of the view.

cacheDisplayInRect:toBitmapImageRep:

Draws the specified area of the view, and its descendants, into a provided bitmap-representation object.

Printing

print:

This action method opens the Print panel, and if the user chooses an option other than canceling, prints the view and all its subviews to the device specified in the Print panel.

beginPageInRect:atPlacement:

Called at the beginning of each page, this method sets up the coordinate system so that a region inside the view’s bounds is translated to a specified location.

dataWithEPSInsideRect:

Returns EPS data that draws the region of the view within a specified rectangle.

dataWithPDFInsideRect:

Returns PDF data that draws the region of the view within a specified rectangle.

printJobTitle

The view’s print job title.

pageHeader

A default header string that includes the print job title and date.

pageFooter

A default footer string that includes the current page number and page count.

writeEPSInsideRect:toPasteboard:

Writes EPS data that draws the region of the view within a specified rectangle onto a pasteboard.

writePDFInsideRect:toPasteboard:

Writes PDF data that draws the region of the view within a specified rectangle onto a pasteboard.

drawPageBorderWithSize:

Allows applications that use the AppKit pagination facility to draw additional marks on each logical page.

drawSheetBorderWithSize:

Allows applications that use the AppKit pagination facility to draw additional marks on each printed sheet.

Pagination

heightAdjustLimit

The fraction of the page that can be pushed onto the next page during automatic pagination to prevent items such as lines of text from being divided across pages.

widthAdjustLimit

The fraction of the page that can be pushed onto the next page during automatic pagination to prevent items such as small images or text columns from being divided across pages.

adjustPageWidthNew:left:right:limit:

Overridden by subclasses to adjust page width during automatic pagination.

adjustPageHeightNew:top:bottom:limit:

Overridden by subclasses to adjust page height during automatic pagination.

knowsPageRange:

Returns YES if the view handles page boundaries, NO otherwise.

rectForPage:

Implemented by subclasses to determine the portion of the view to be printed for the specified page number.

locationOfPrintRect:

Invoked by print: to determine the location of the region of the view being printed on the physical page.

Invalidating the View’s Content

setNeedsDisplayInRect:

Marks the region of the view within the specified rectangle as needing display, increasing the view’s existing invalid region to include it.

needsDisplay

A Boolean value that determines whether the view needs to be redrawn before being displayed.

display

Displays the view and all its subviews if possible, invoking each of the NSView methods lockFocus, drawRect:, and unlockFocus as necessary.

displayRect:

Acts as display, but confining drawing to a rectangular region of the view.

displayRectIgnoringOpacity:

Displays the view but confines drawing to a specified region and does not back up to the first opaque ancestor—it simply causes the view and its descendants to execute their drawing code.

displayRectIgnoringOpacity:inContext:

Causes the view and its descendants to be redrawn to the specified graphics context.

displayIfNeeded

Displays the view and all its subviews if any part of the view has been marked as needing display.

displayIfNeededInRect:

Acts as displayIfNeeded, confining drawing to a specified region of the view.

displayIfNeededIgnoringOpacity

Acts as displayIfNeeded, except that this method doesn’t back up to the first opaque ancestor—it simply causes the view and its descendants to execute their drawing code.

displayIfNeededInRectIgnoringOpacity:

Acts as displayIfNeeded, but confining drawing to aRect and not backing up to the first opaque ancestor—it simply causes the view and its descendants to execute their drawing code.

translateRectsNeedingDisplayInRect:by:

Translates the display rectangles by the specified delta.

opaque

A Boolean value indicating whether the view fills its frame rectangle with opaque content.

viewWillDraw

Informs the view that it will be required to draw content.

Converting Coordinate Values

backingAlignedRect:options:

Returns a backing store pixel-aligned rectangle in local view coordinates.

convertPointFromBacking:

Converts a point from its pixel aligned backing store coordinate system to the view’s interior coordinate system.

convertPointToBacking:

Converts a point from the view’s interior coordinate system to its pixel aligned backing store coordinate system.

convertPointFromLayer:

Convert the point from the layer's interior coordinate system to the view’s interior coordinate system.

convertPointToLayer:

Convert the size from the view’s interior coordinate system to the layer's interior coordinate system.

convertRectFromBacking:

Converts a rectangle from its pixel aligned backing store coordinate system to the view’s interior coordinate system.

convertRectToBacking:

Converts a rectangle from the view’s interior coordinate system to its pixel aligned backing store coordinate system.

convertRectFromLayer:

Convert the rectangle from the layer's interior coordinate system to the view’s interior coordinate system.

convertRectToLayer:

Convert the size from the view’s interior coordinate system to the layer's interior coordinate system.

convertSizeFromBacking:

Converts a size from its pixel aligned backing store coordinate system to the view’s interior coordinate system.

convertSizeToBacking:

Converts a size from the view’s interior coordinate system to its pixel aligned backing store coordinate system.

convertSizeFromLayer:

Convert the size from the layer's interior coordinate system to the view’s interior coordinate system.

convertSizeToLayer:

Convert the size from the view’s interior coordinate system to the layer's interior coordinate system.

convertPoint:fromView:

Converts a point from the coordinate system of a given view to that of the view.

convertPoint:toView:

Converts a point from the view’s coordinate system to that of a given view.

convertSize:fromView:

Converts a size from another view’s coordinate system to that of the view.

convertSize:toView:

Converts a size from the view’s coordinate system to that of another view.

convertRect:fromView:

Converts a rectangle from the coordinate system of another view to that of the view.

convertRect:toView:

Converts a rectangle from the view’s coordinate system to that of another view.

centerScanRect:

Converts the corners of a specified rectangle to lie on the center of device pixels, which is useful in compensating for rendering overscanning when the coordinate system has been scaled.

Modifying the Coordinate System

translateOriginToPoint:

Translates the view’s coordinate system so that its origin moves to a new location.

scaleUnitSquareToSize:

Scales the view’s coordinate system so that the unit square scales to the specified dimensions.

rotateByAngle:

Rotates the view’s bounds rectangle by a specified degree value around the origin of the coordinate system, (0.0, 0.0).

Examining Coordinate System Modifications

flipped

A Boolean value indicating whether the view uses a flipped coordinate system.

rotatedFromBase

A Boolean value indicating whether the view or any of its ancestors has ever had a rotation factor applied to its frame or bounds.

rotatedOrScaledFromBase

A Boolean value indicating whether the view or any of its ancestors has ever had a rotation factor applied to its frame or bounds, or has been scaled from the window’s base coordinate system.

Resizing Subviews

autoresizesSubviews

A Boolean value indicating whether the view applies the autoresizing behavior to its subviews when its frame size changes.

autoresizingMask

The options that determine how the view is resized relative to its superview.

resizeSubviewsWithOldSize:

Informs the view’s subviews that the view’s bounds rectangle size has changed.

resizeWithOldSuperviewSize:

Informs the view that the bounds size of its superview has changed.

Creating Constraints Using Layout Anchors

bottomAnchor

A layout anchor representing the bottom edge of the view’s frame.

centerXAnchor

A layout anchor representing the horizontal center of the view’s frame.

centerYAnchor

A layout anchor representing the vertical center of the view’s frame.

firstBaselineAnchor

A layout anchor representing the baseline for the topmost line of text in the view.

heightAnchor

A layout anchor representing the height of the view’s frame.

lastBaselineAnchor

A layout anchor representing the baseline for the bottommost line of text in the view.

leadingAnchor

A layout anchor representing the leading edge of the view’s frame.

leftAnchor

A layout anchor representing the left edge of the view’s frame.

rightAnchor

A layout anchor representing the right edge of the view’s frame.

topAnchor

A layout anchor representing the top edge of the view’s frame.

trailingAnchor

A layout anchor representing the trailing edge of the view’s frame.

widthAnchor

A layout anchor representing the width of the view’s frame.

Managing the View’s Constraints

constraints

Returns the constraints held by the view.

addConstraint:

Adds a constraint on the layout of the receiving view or its subviews.

addConstraints:

Adds multiple constraints on the layout of the receiving view or its subviews.

removeConstraint:

Removes the specified constraint from the view.

removeConstraints:

Removes the specified constraints from the view.

Working with Layout Guides

addLayoutGuide:

Adds the provided layout guide to the view.

layoutGuides

The array of layout guide objects owned by this view.

removeLayoutGuide:

Removes the provided layout guide from the view.

Measuring in Auto Layout

fittingSize

The minimum size of the view that satisfies the constraints it holds.

intrinsicContentSize

The natural size for the receiving view, considering only properties of the view itself.

invalidateIntrinsicContentSize

Invalidates the view’s intrinsic content size.

contentCompressionResistancePriorityForOrientation:

Returns the priority with which a view resists being made smaller than its intrinsic size.

setContentCompressionResistancePriority:forOrientation:

Sets the priority with which a view resists being made smaller than its intrinsic size.

contentHuggingPriorityForOrientation:

Returns the priority with which a view resists being made larger than its intrinsic size.

setContentHuggingPriority:forOrientation:

Sets the priority with which a view resists being made larger than its intrinsic size.

Aligning Views with Auto Layout

alignmentRectForFrame:

Returns the view’s alignment rectangle for a given frame.

frameForAlignmentRect:

Returns the view’s frame for a given alignment rectangle.

alignmentRectInsets

The insets (in points) from the view’s frame that define its content rectangle.

baselineOffsetFromBottom

The distance (in points) between the bottom of the view’s alignment rectangle and its baseline.

firstBaselineOffsetFromTop

The distance (in points) between the top of the view’s alignment rectangle and its topmost baseline.

lastBaselineOffsetFromBottom

The distance (in points) between the bottom of the view’s alignment rectangle and its bottommost baseline.

Triggering Auto Layout

needsLayout

A Boolean value indicating whether the view needs a layout pass before it can be drawn.

layout

Perform layout in concert with the constraint-based layout system.

layoutSubtreeIfNeeded

Updates the layout of the receiving view and its subviews based on the current views and constraints.

needsUpdateConstraints

A Boolean value indicating whether the view’s constraints need to be updated.

updateConstraints

Update constraints for the view.

updateConstraintsForSubtreeIfNeeded

Updates the constraints for the receiving view and its subviews.

Opting In to Auto Layout

requiresConstraintBasedLayout

Returns a Boolean value indicating whether the view depends on the constraint-based layout system.

translatesAutoresizingMaskIntoConstraints

A Boolean value indicating whether the view’s autoresizing mask is translated into constraints for the constraint-based layout system.

Debugging Auto Layout

See Auto Layout Guide for more details on debugging constraint-based layout.

constraintsAffectingLayoutForOrientation:

Returns the constraints impacting the layout of the view for a given orientation.

hasAmbiguousLayout

A Boolean value indicating whether the constraints impacting the layout of the view incompletely specify the location of the view.

exerciseAmbiguityInLayout

Randomly changes the frame of a view with an ambiguous layout between the different valid values.

Focusing

lockFocus

Locks the focus on the view, so subsequent commands take effect in the view’s window and coordinate system.

lockFocusIfCanDraw

Locks the focus to the view atomically if the canDraw method returns YES and returns the value of canDraw.

lockFocusIfCanDrawInContext:

Locks the focus to the view atomically if drawing can occur in the specified graphics context.

Deprecated
unlockFocus

Unlocks focus from the current view.

focusView

Returns the currently focused NSView object, or nil if there is none.

Focus Ring Drawing

focusRingType

The type of focus ring drawn around the view.

focusRingMaskBounds

The focus ring mask bounds, specified in the view’s coordinate space.

drawFocusRingMask

Draws the focus ring mask for the view.

noteFocusRingMaskChanged

Invoked to notify the view that the focus ring mask requires updating.

setKeyboardFocusRingNeedsDisplayInRect:

Invalidates the area around the focus ring.

defaultFocusRingType

Returns the default focus ring type.

Getting the Vibrancy Setting

allowsVibrancy

A Boolean value indicating whether the view ensures it is vibrant on top of other content.

Fullscreen Mode

enterFullScreenMode:withOptions:

Sets the view to full screen mode.

exitFullScreenModeWithOptions:

Instructs the view to exit full screen mode.

inFullScreenMode

A Boolean value indicating whether the view is in full screen mode.

Hiding Views

hidden

A Boolean value indicating whether the view is hidden.

hiddenOrHasHiddenAncestor

A Boolean value indicating whether the view is hidden from sight because it, or one of its ancestors, is marked as hidden.

viewDidHide

Invoked when the view is hidden, either directly, or in response to an ancestor being hidden.

viewDidUnhide

Invoked when the view is unhidden, either directly, or in response to an ancestor being unhidden

Managing Live Resize

inLiveResize

A Boolean value indicating whether the view is being rendered as part of a live resizing operation.

preservesContentDuringLiveResize

A Boolean value indicating whether the view optimizes live-resize operations by preserving content that has not moved.

getRectsExposedDuringLiveResize:count:

Returns a list of rectangles indicating the newly exposed areas of the view.

rectPreservedDuringLiveResize

The rectangle identifying the portion of your view that did not change during a live resize operation.

viewWillStartLiveResize

Informs the view of the start of a live resize—the user has started resizing the view.

viewDidEndLiveResize

Informs the view of the end of a live resize—the user has finished resizing the view.

Managing Gesture Recognizers

gestureRecognizers

The gesture recognize objects currently attached to the view.

addGestureRecognizer:

Attaches a gesture recognizer to the view.

removeGestureRecognizer:

Detaches a gesture recognizer from the view.

Event Handling

acceptsFirstMouse:

Overridden by subclasses to return YES if the view should be sent a mouseDown: message for an initial mouse-down event, NO if not.

hitTest:

Returns the farthest descendant of the view in the view hierarchy (including itself) that contains a specified point, or nil if that point lies completely outside the view.

mouse:inRect:

Returns whether a region of the view contains a specified point, accounting for whether the view is flipped or not.

performKeyEquivalent:

Implemented by subclasses to respond to key equivalents (also known as keyboard shortcuts).

rightMouseDown:

Informs the view that the user has pressed the right mouse button.

mouseDownCanMoveWindow

A Boolean value indicating whether the view can pass mouse down events through to its superviews.

inputContext

The text input context object for the view.

Touch Event Handling

acceptsTouchEvents

A Boolean value indicating whether the view accepts touch events.

Deprecated
wantsRestingTouches

A Boolean value indicating whether the view wants resting touches.

Key-view Loop Management

canBecomeKeyView

A Boolean value indicating whether the view can become key view.

needsPanelToBecomeKey

A Boolean value indicating whether the view needs its panel to become the key window before it can handle keyboard input and navigation.

nextKeyView

The view object that follows the current view in the key view loop.

nextValidKeyView

The closest view object in the key view loop that follows the current view in the key view loop and accepts first responder status.

previousKeyView

The view object preceding the current view in the key view loop.

previousValidKeyView

The closest view object in the key view loop that precedes the current view and accepts first responder status.

Scrolling

prepareContentInRect:

Prepares the overdraw region for drawing.

preparedContentRect

The portion of the view that has been rendered and is available for responsive scrolling.

scrollPoint:

Scrolls the view’s closest ancestor NSClipView object so a point in the view lies at the origin of the clip view's bounds rectangle.

scrollRectToVisible:

Scrolls the view’s closest ancestor NSClipView object the minimum distance needed so a specified region of the view becomes visible in the clip view.

autoscroll:

Scrolls the view’s closest ancestor NSClipView object proportionally to the distance of an event that occurs outside of it.

adjustScroll:

Overridden by subclasses to modify a given rectangle, returning the altered rectangle.

scrollRect:by:

Copies the visible portion of the view’s rendered image within a region and lays that portion down again at a specified offset .

enclosingScrollView

The nearest ancestor scroll view that contains the current view.

scrollClipView:toPoint:

Notifies the superview of a clip view that the clip view needs to reset the origin of its bounds rectangle.

reflectScrolledClipView:

Notifies a clip view’s superview that either the clip view’s bounds rectangle or the document view’s frame rectangle has changed, and that any indicators of the scroll position need to be adjusted.

Dragging Operations

registerForDraggedTypes:

Registers the pasteboard types that the view will accept as the destination of an image-dragging session.

unregisterDraggedTypes

Unregisters the view as a possible destination in a dragging session.

registeredDraggedTypes

The array of pasteboard drag types that the view can accept.

beginDraggingSessionWithItems:event:source:

Initiates a dragging session with a group of dragging items.

dragFile:fromRect:slideBack:event:

Initiates a dragging operation from the view, allowing the user to drag a file icon to any application that has window or view objects that accept files.

Deprecated
dragPromisedFilesOfTypes:fromRect:source:slideBack:event:

Initiates a dragging operation from the view, allowing the user to drag one or more promised files (or directories) into any application that has window or view objects that accept promised file data.

Deprecated
shouldDelayWindowOrderingForEvent:

Allows the user to drag objects from the view without activating the app or moving the window of the view forward, possibly obscuring the destination.

Handling Smart Magnification

rectForSmartMagnificationAtPoint:inRect:

Returns the appropriate rectangle to use when magnifying around the specified point.

Controlling Notifications

postsFrameChangedNotifications

A Boolean value indicating whether the view posts notifications when its frame rectangle changes.

postsBoundsChangedNotifications

A Boolean value indicating whether the view posts notifications when its bounds rectangle changes.

Responding to Changes in Backing Store Properties

viewDidChangeBackingProperties

Responds when the view’s backing store properties change.

Searching by Tag

viewWithTag:

Returns the view’s nearest descendant (including itself) with a specific tag, or nil if no subview has that tag.

tag

The view’s tag, which is an integer that you use to identify the view within your app.

Tooltips

addToolTipRect:owner:userData:

Creates a tooltip for a defined area the view and returns a tag that identifies the tooltip rectangle.

removeAllToolTips

Removes all tooltips assigned to the view.

removeToolTip:

Removes the tooltip identified by specified tag.

toolTip

The text for the view’s tooltip.

Managing Tracking Rectangles

addTrackingRect:owner:userData:assumeInside:

Establishes an area for tracking mouse-entered and mouse-exited events within the view and returns a tag that identifies the tracking rectangle.

removeTrackingRect:

Removes the tracking rectangle identified by a tag.

Managing Tracking Areas

addTrackingArea:

Adds a given tracking area to the view.

removeTrackingArea:

Removes a given tracking area from the view.

trackingAreas

An array of the view’s tracking areas.

updateTrackingAreas

Invoked automatically when the view’s geometry changes such that its tracking areas need to be recalculated.

Managing Cursor Tracking

addCursorRect:cursor:

Establishes the cursor to be used when the mouse pointer lies within a specified region.

removeCursorRect:cursor:

Completely removes a cursor rectangle from the view.

discardCursorRects

Invalidates all cursor rectangles set up using addCursorRect:cursor:.

resetCursorRects

Overridden by subclasses to define their default cursor rectangles.

Managing Contextual Menus

menuForEvent:

Overridden by subclasses to return a context-sensitive pop-up menu for a given mouse-down event.

defaultMenu

Overridden by subclasses to return the default pop-up menu for instances of the receiving class.

willOpenMenu:withEvent:

Called just before a contextual menu for a view is opened on screen.

didCloseMenu:withEvent:

Called after a contextual menu that was displayed from the receiving view has been closed.

Writing Conforming Rendering Instructions

beginDocument

Invoked at the beginning of the printing session, this method sets up the current graphics context.

endDocument

This method is invoked at the end of the printing session.

endPage

Writes the end of a conforming page.

Displaying Definition Windows

showDefinitionForAttributedString:atPoint:

Shows a window displaying the definition of the attributed string at the specified point.

showDefinitionForAttributedString:range:options:baselineOriginProvider:

Shows a window displaying the definition of the specified range of the attributed string.

Drawing Find Indicator

drawingFindIndicator

A Boolean value indicating whether the view or one of its ancestors is being drawn for a find indicator.

Managing the Content Layout Direction

userInterfaceLayoutDirection

The layout direction for content in the view.

Specifying the OpenGL Surface Resolution

wantsBestResolutionOpenGLSurface

A Boolean value indicating whether the view wants an OpenGL backing surface with a resolution greater than 1 pixel per point.

Configuring Pressure

pressureConfiguration

Configures the behavior and progression of the Force Touch trackpad when responding to touch input produced by the user when the cursor is over the view.

Deprecated Methods

convertPointToBase:

Converts the point from the view’s coordinate system to the base coordinate system.

Deprecated
convertPointFromBase:

Converts the point from the base coordinate system to the view’s coordinate system.

Deprecated
convertSizeToBase:

Converts the size from the view’s coordinate system to the base coordinate system.

Deprecated
convertSizeFromBase:

Converts the size from the base coordinate system to the view’s coordinate system.

Deprecated
convertRectToBase:

Converts the rectangle from the view’s coordinate system to the base coordinate system.

Deprecated
convertRectFromBase:

Converts the rectangle from the base coordinate system to the view’s coordinate system.

Deprecated
performMnemonic:

Implemented by subclasses to respond to mnemonics.

Deprecated
shouldDrawColor

Returns a Boolean value indicating whether the view is being drawn to an environment that supports color.

Deprecated
allocateGState

Causes the view to maintain a private graphics state object, which encapsulates all parameters of the graphics environment.

Deprecated
gState

Returns the identifier for the view’s graphics state object, or 0 if the view doesn’t have a graphics state object.

Deprecated
setUpGState

Overridden by subclasses to (re)initialize the view’s graphics state object.

Deprecated
renewGState

Invalidates the view’s graphics state object, if it has one.

Deprecated
releaseGState

Frees the view’s graphics state object, if it has one.

Deprecated
dragImage:at:offset:event:pasteboard:source:slideBack:

Initiates a dragging operation from the view, allowing the user to drag arbitrary data with a specified icon into any application that has window or view objects that accept dragged data.

Deprecated

Constants

NSBorderType

These constants specify the type of a view’s border.

NSAutoresizingMaskOptions

Constants used by the autoresizingMask property.

NSToolTipTag

This type describes the rectangle used to identify a tooltip rectangle.

NSTrackingRectTag

This type describes the rectangle used to track the mouse.

Full Screen Mode Options

These constants are keys that you can use in the options dictionary in enterFullScreenMode:withOptions: and exitFullScreenModeWithOptions:.

NSViewLayerContentsRedrawPolicy

Constants that specify how layer resizing is handled when a view is layer-backed or layer-hosting. For more information, see the layerContentsRedrawPolicy property.

NSViewLayerContentsPlacement

These constants specify the location of the layer content when the content is not re-rendered in response to view resizing. For more information, see the layerContentsPlacement property.

NSDefinition Presentation Constants

These constants are used to control how definition windows are displayed by showDefinitionForAttributedString:range:options:baselineOriginProvider:. If this option is unspecified, the definition will be shown in either of those presentation forms depending on the 'Contextual Menu:' setting in Dictionary application preferences.

NSView Intrinsic Metric Constant

Used to indicate that a view has no intrinsic metric for a given numeric property.

Notifications

NSViewBoundsDidChangeNotification

Posted whenever the NSView’s bounds rectangle changes to a new value independently of the frame rectangle, but only when the view’s postsBoundsChangedNotifications property is YES.

NSViewFocusDidChangeNotification

Deprecated in macOS 10.4 and later. Posted for an NSView object and each of its descendants (recursively) whenever the frame or bounds geometry of the view changed.

Deprecated
NSViewFrameDidChangeNotification

Posted whenever the view’s frame rectangle changes to a new value, but only when the view’s postsFrameChangedNotifications property is YES.

NSViewDidUpdateTrackingAreasNotification

Posted whenever an NSView object recalculates its tracking areas.

NSViewGlobalFrameDidChangeNotification

Posted whenever an NSView object that has attached surfaces (that is, NSOpenGLContext objects) moves to a different screen, or other cases where the NSOpenGLContext object needs to be updated.

Initializers

Instance Methods

rulerView:didAddMarker:

Informs the client that aRulerView allowed the user to add aMarker.

rulerView:didMoveMarker:

Informs the client that aRulerView allowed the user to move aMarker.

rulerView:didRemoveMarker:

Informs the client that aRulerView allowed the user to remove aMarker.

rulerView:handleMouseDown:

Informs the client that the user has pressed the mouse button while the cursor is in the ruler area of aRulerView.

rulerView:shouldAddMarker:

Requests permission for aRulerView to add aMarker, an NSRulerMarker being dragged onto the ruler by the user.

rulerView:shouldMoveMarker:

Requests permission for aRulerView to move aMarker.

rulerView:shouldRemoveMarker:

Requests permission for aRulerView to remove aMarker.

rulerView:willAddMarker:atLocation:

Informs the client that aRulerView will add the new NSRulerMarker, aMarker.

rulerView:willMoveMarker:toLocation:

Informs the client that aRulerView will move aMarker, an NSRulerMarker already on the ruler view.

rulerView:willSetClientView:

Informs the client view that aRulerView is about to be appropriated by newClient.

See Also

First Steps

NSControl

A definition of the fundamental behavior for controls, which are specialized views that notify your app of relevant events by using the target-action design pattern.

NSCell

A mechanism for displaying text or images in a view object without the overhead of a full NSView subclass.

NSActionCell

An active area inside a control.