Instance Method

lockFocus

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

Declaration

- (void)lockFocus;

Discussion

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 YES; you can also call lockFocusIfCanDraw instead and use the return value of that method to determine if focus was obtained successfully.

See Also

Focusing

- lockFocusIfCanDraw

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

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

Deprecated
focusView

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