Contents

lockFocus()

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

Declaration

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

See Also

Related Documentation

Methods