How to rotate a UIImageView – ios sdk roulette tutorial

Animating an object using the ios sdk is very simple, but it's very difficult to retrieve an howto on the internet. So here you are a simple example

In this simple tutorial I'm going show to you how run a roulette, first of all we need the roulette, we will use the following image:

Now open Xcode and create a new project, you can choose "Single View Application" as your template.

Drag the image into the project.

Select the storyboard and insert a UIImageView and a Round Rect Button.

Open the ViewController.h header file and modify it, it should look like the following:

Open the ViewController.m file and just after insert the following code:

Into the viewDidLoad method, before the   [super viewDidLoad]; statement add the following two lines to initialize the roulette values
    angle = 0;
    runStop = FALSE;

Now go to the storyboard,  right click on the "View Controller" and drag on the button, in the popop menu that will appear select theButton; right t click on the "View Controller" and drag on the UIImageView  in the popop menu that will appear select theImageView; right click on the button and drag on the "View Controller", in the popup menu that will appear select "runRoulette:".

That's all, now run your project, and try to tap on the button you should see the roulette rotating and stopping.


Releated Post

7 thoughts on “How to rotate a UIImageView – ios sdk roulette tutorial

  1. Hi,
    im missing something.  It sort of glides down to the right then back up to the top left as its spinning.

  2. Hello, thank you for your help. I got using my code and it worked, but the image does not rotate properly, it's a difference in rotation axis is not fixed in the middle of the image, rotate the image besides also is moving sideways. Can you help me solve this problem? must rotate at the image own axis, and not only rotate to move laterally. Anyway thanks for the help. Alex

  3. Hi

    I have the same problem that the image shunts up/down and side to side as it rotates. Is there a bug somewhere? or is it due to initailistaion of the centre co-ordinates. Any help much appreciated



  4. Terence, for what I remember, the problem is due to the coordinates of the rotation centre.

    Please post the centre of the coordinates, if you’ll find the correct values.

Leave a Reply

Your email address will not be published. Required fields are marked *