0

I am very new to objective C and iPhone app development. I have experience in PHP and java and obviously this language is very different. Right now what I'm trying to do is rotate an arrow when its touched.

All I need is a method that rotates the image, and then the code (and where it goes) that keeps the touch listener (or whatever its called) in the "main" method (like java)

Sorry if my terminology is wrong.

Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Well, the easiest way is to apply a transform. Let's say you have an image view called imageView and button target action to apply the transform. And that handler is called rotateImage:. The code would look like:

 - (IBAction)rotateImage:(id)sender
 {
     self.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);
 }

If you are using interface builder you'd just set a target action to the button in your view controller.

Keep in mind that the rotation transform is in radians, so the above would be a 90deg rotation. You need calculate the correct radians for however many degrees you want to rotate.

If you are adding the button programmatically, you would add the target handler in code with:

[button addTarget:self action:@selector(rotateImage:) forControlEvents:UIControlEventTouchUpInside];
Bladebunny
  • 1,251
  • 9
  • 12