Another explanation which might help those seeking clarity…
[I may be especially dense on this topic but I didn’t find Joe’s explanation very much more helpful than the documentation so I had to experiment my way to understanding. The problem, I hope, is that I have no idea what the point of contentsRect is and so the way it works is just some sort of magic. Of course the explanations (and documentation) are clear once I understood it (still don’t know what purpose it serves!), but… If the preceding posts aren’t clear for those reading the forum, perhaps a different explanation will help.]
Your image exists in what the documentation calls “the unit coordinate space” and the coordinates in that space are not pixels or points. In this space the image occupies a square with origin (upper left corner) at (0, 0) with both width and height of 1.0. The axes “scale” are relative to the size of the image – X and Y axes can be different.
The value of contentsRect specifies which rectangular area from this “unit coordinate space” should be drawn (i.e. mapped to) the layer.
This rectangle can be the whole image,
part of the image,
or, the case in the book, it can include the image and also parts of the space that lie outside the image.
The default contentsRect of (0, 0, 1, 1) is the whole image.
The contentsRect value (0.25, 0.25, 0.5 0.5), for example, would show part of the image –
a central rectangle of the image.
The contentsRect setting in the book, (-0.1, -0.1, 1.2, 1.2) includes parts of the
coordinate space outside the image itself. The corners of that rectangle are:
(-0.1, -0.1) – (1.1, -0.1)
(-0.1, 1.1) – (1.1, 1.1)
So there is 0.1 of “extra space” on each border – i.e. 1/10th the dimension of the image in that axis.
When contentsRect includes space outside the image like this the pixels drawn in the layer
have to come from somewhere. Joe called it “whitespace”, and for Hypno.png that is the effect,
but what really happens is that:
“If pixels outside the unit rectangle are requested, the edge pixels of the contents image will be extended outwards.”
If this too is “clear as mud” then experimenting with various rectangles should help you.