| Inherits from | |
| Conforms to |
NSCoding (NSResponder) NSObject (NSObject) NSUserInterfaceItemIdentification NSAnimatablePropertyContainer |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in Mac OS X v10.0 and later.
|
| Declared in | NSClipView.h NSMenuItem.h NSView.h |
| Companion guides |
NSView is an abstract class that defines the basic drawing, event-handling, and printing architecture of an application. You typically don’t interact with the NSView API directly; rather, your custom view classes inherit from NSView and override many of its methods, which are invoked automatically by the Application Kit. If you’re not creating a custom view class, there are few methods you need to use.
Event handling
Integrated display to screen and printer
Flexible coordinate systems
Icon dragging
frameReturns the location and size of the NSView object.
boundsReturns the internal origin and size of the NSView object.
setNeedsDisplay:Marks the NSView object as needing to be redrawn
windowReturns 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.)
NSView is an abstract class that provides concrete subclasses with a structure for drawing, printing, and handling events.
NSView objects (also know, simply, as view objects or views) are arranged within an NSWindow object, in a nested hierarchy of subviews. A view object claims a rectangular region of its enclosing superview, is responsible for all drawing within that region, and is eligible to receive mouse events occurring in it as well. In addition to these major responsibilities, NSView handles dragging of icons and works with the NSScrollView class to support efficient scrolling.
Most of the functionality of NSView either is automatically invoked by the Application Kit, or is available in Interface Builder. 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. See “Commonly Used Methods” for methods you might use regardless.
For more information on how NSView instances handle event and action messages, see Handling Events in Views, Handling Mouse Events in Views, and Handling Tracking-Rectangle and Cursor-Update Events in Views. For more information on displaying tooltips and contextual menus, see How Contextual Menus Work and Tooltips.
NSView is perhaps the most important class in the Application Kit 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 Events in Views" and "Handling Mouse Events in Views").
– superview
– setSubviews:
– subviews
– window
– addSubview:
– addSubview:positioned:relativeTo:
– didAddSubview:
– removeFromSuperview
– removeFromSuperviewWithoutNeedingDisplay
– replaceSubview:with:
– isDescendantOf:
– opaqueAncestor
– ancestorSharedWithView:
– sortSubviewsUsingFunction:context:
– viewDidMoveToSuperview
– viewDidMoveToWindow
– viewWillMoveToSuperview:
– viewWillMoveToWindow:
– willRemoveSubview:
– enclosingMenuItem
– convertPointToBase:
– convertPointFromBase:
– convertSizeToBase:
– convertSizeFromBase:
– convertRectToBase:
– convertRectFromBase:
– convertPoint:fromView:
– convertPoint:toView:
– convertSize:fromView:
– convertSize:toView:
– convertRect:fromView:
– convertRect:toView:
– centerScanRect:
– setPostsFrameChangedNotifications:
– postsFrameChangedNotifications
– setPostsBoundsChangedNotifications:
– postsBoundsChangedNotifications
– resizeSubviewsWithOldSize:
– resizeWithOldSuperviewSize:
– setAutoresizesSubviews:
– autoresizesSubviews
– setAutoresizingMask:
– autoresizingMask
– setNeedsDisplay:
– setNeedsDisplayInRect:
– needsDisplay
– display
– displayRect:
– displayRectIgnoringOpacity:
– displayRectIgnoringOpacity:inContext:
– displayIfNeeded
– displayIfNeededInRect:
– displayIfNeededIgnoringOpacity
– displayIfNeededInRectIgnoringOpacity:
– translateRectsNeedingDisplayInRect:by:
– isOpaque
– viewWillDraw
– setKeyboardFocusRingNeedsDisplayInRect:
+ defaultFocusRingType
– setFocusRingType:
– focusRingType
– drawRect:
– visibleRect
– canDraw
– shouldDrawColor
– getRectsBeingDrawn:count:
– needsToDrawRect:
– wantsDefaultClipping
– bitmapImageRepForCachingDisplayInRect:
– cacheDisplayInRect:toBitmapImageRep:
– inLiveResize
– preservesContentDuringLiveResize
– getRectsExposedDuringLiveResize:count:
– rectPreservedDuringLiveResize
– viewWillStartLiveResize
– viewDidEndLiveResize
– acceptsFirstMouse:
– hitTest:
– mouse:inRect:
– performKeyEquivalent:
– performMnemonic:
– mouseDownCanMoveWindow
– dragImage:at:offset:event:pasteboard:source:slideBack:
– dragFile:fromRect:slideBack:event:
– registerForDraggedTypes:
– registeredDraggedTypes
– unregisterDraggedTypes
– shouldDelayWindowOrderingForEvent:
– dragPromisedFilesOfTypes:fromRect:source:slideBack:event:
– scrollPoint:
– scrollRectToVisible:
– autoscroll:
– adjustScroll:
– scrollRect:by:
– enclosingScrollView
– scrollClipView:toPoint:
– reflectScrolledClipView:
– canBecomeKeyView
– needsPanelToBecomeKey
– setNextKeyView:
– nextKeyView
– nextValidKeyView
– previousKeyView
– previousValidKeyView
– print:
– beginPageInRect:atPlacement:
– dataWithEPSInsideRect:
– dataWithPDFInsideRect:
– printJobTitle
– pageFooter
– pageHeader
– writeEPSInsideRect:toPasteboard:
– writePDFInsideRect:toPasteboard:
– drawPageBorderWithSize:
– drawSheetBorderWithSize: