Instance Method


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


func lockFocus()


If you don’t use a display method to draw an NSView object, you must invoke lockFocus() before invoking methods that send commands to the window server, and must balance it with an unlockFocus() message when finished.

Hiding or miniaturizing a one-shot window causes the backing store for that window to be released. (A one-shot window frees its window device when the window is hidden and another is created when it’s returned to the screen.) If you don’t use the standard display mechanism to draw, you should use lockFocusIfCanDraw() rather than lockFocus() if there is a chance of drawing while the window is either miniaturized or hidden. This method throws an exception if the view is hidden or if drawing cannot happen for some other reason. To ensure that you can lock focus successfully, make sure the canDraw property is true; you can also call lockFocusIfCanDraw() instead and use the return value of that method to determine if focus was obtained successfully.

See Also


func lockFocusIfCanDraw() -> Bool

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

func lockFocusIfCanDraw(in: NSGraphicsContext) -> Bool

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

func unlockFocus()

Unlocks focus from the current view.

class var focusView: NSView?

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