views:

278

answers:

3

In particular, I am adding a compass to my app.

I want to place an arrow that rotates on top of a circular compass background. If you could link me to anything that describes stacking/superimposing images, I'd be grateful.

I couldn't seem to find much via Google.

A: 

You'll could use two UIImages, the 'needle' one, and the compass one. If you use a PNG or GIF for the needle one, and Core Animation to rotate it, you can specify which goes on top in Interface Builder with the menu item Layout->Send Forward (or Layout->Send Backward)

Here's apple's doc on Interface Builder:

http://devworld.apple.com/documentation/DeveloperTools/Conceptual/IB_UserGuide/Introduction/Introduction.html

John
+3  A: 

Use a couple of UIImageViews, one for the compass background, and one for the arrow, and add them to your main application view. You should have something like this in some method in your main view controller:

compassBackground = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"compassBackground.png"]];
arrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
[compassBackground addSubview:arrow];
[self.view addSubview:compassBackground];

Of course, compassBackground and arrow are members of your view controller class. To animate the arrow, apply an affine transformation to the view:

arrow.transform = CGAffineTransformMakeRotation(angleInRadians);

If you are building your main view with Interface Builder, it is even easier: add the compass background and arrow to the view, connect them to the controller, and apply the transformation as explained above.

Marco Mustapic
A: 

New to iPhone app development. The code you show for adding images, where would that be added? The nib file? or the .h file? Or other? Thanks in advance.

huh? are you asking a question to Marco? If so, that code would go in the .m file (.h is just a header/definition, .nib is for interface objects - no "code" is user-written there).
Erich Mirabal