C H A P T E R 1 3
Drawing and Graphics
Using the Drawing Interface
If you want to redraw a view explicitly at any particular time, you need to send it
message. This message causes the system to add that view to the area of
the screen that it updates in the next event loop cycle. To make the update area
redraw before the next event loop cycle, you must call the
function after sending the
If you want to draw in a view at times other than when the view is being opened
or redrawn automatically, you can execute drawing code outside of the
method by using
. For example, you might need
to perform your own drawing operations immediately when the user taps in the view.
You can use the
method for this purpose. The
calls another drawing method that you supply as one of its arguments.
W A R N I N G
Do not directly use
to draw shapes outside
. Standard drawing in
up the drawing environment. If you use
setting up the drawing environment, your application could
accidentally draw on top of other applications, keyboards,
Using Nested Arrays of Shapes
method can draw multiple shapes when passed an array of shapes
as its argument. Style frames may be included in the shape array to change the
drawing style used to image subsequent elements of the array. Each element of
the array can itself be an array as well; this section refers to such an array as a
Styles are maintained on a per-array basis in nested arrays, and the startStyle
is always treated as though it were the first array
element of the topmost array. Therefore, compound shapes and multiple styles
remain intact when nested arrays are combined into larger groupings.
method processes a nested array, the shapes are drawn in
ascending element order and drawing begins with the style of the parent array.
Although the drawing style may change while processing the elements of an
individual array, that style applies only to the elements of that particular array.
Therefore, if an array happens to be an element of another array--that is, a nested
array--style changes in the nested array affect the processing of its subsequent
elements but the drawing style of the parent array is restored after the last element
of the nested array is processed.