Rotate UIImageView in xcode

I wish to create a swirl affect when displaying an image in xcode (for the iPhone).

I have the image "swelling" and "shrinking", but when I apply CGAffineTransformMakeRotation the image seems to rotate around x and y axis' (as well as swell and shrink).

I simply, about the center point, wish to have it spin around and around.  

LIke I said, it spins but appears to be spinning in 3D.
Sheldon LivingstonConsultantAsked:
Who is Participating?
From what you are showing in that code, it seems like "thePie" is simply rotating on it's top left corner.  Add "thePie" to a blank UIView like I described in my code, and then rotate that instead of "thePie".  You can apply other effects directly to "thePie", just not the rotation transformation.
So are you looking to rotate the image around a center point?  Could you post what you have now?
Sheldon LivingstonConsultantAuthor Commented:
From the center point... like a pinwheel
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

One way that you can do this is overlay the UIImageView on a separate UIView, and then rotate that.  Perhaps something like below:

    UIView *view_to_rotate = [[UIView alloc] init];
    [view_to_rotate setFrame:CGRectMake(150, 200, 1, 1)];
    [view_to_rotate setClipsToBounds:NO];
    UIImageView *content_view = [[UIImageView alloc] init];
    CGFloat imageHeight = 200;
    CGFloat imageWidth = 200;
    [content_view setFrame:CGRectMake((imageWidth / 2) * -1, (imageHeight / 2) * -1, imageHeight, imageWidth)];
    [content_view setBackgroundColor:[UIColor blueColor]];
    [view_to_rotate addSubview:content_view];
    [content_view release];
    [self.view addSubview:view_to_rotate];
    [UIView animateWithDuration:1.0 animations:^(void) {
        [view_to_rotate setTransform:CGAffineTransformMakeRotation(3.1415926535)];
    [view_to_rotate release];

Open in new window

If you run the code above, you will notice that it rotates a blue square around the middle instead of the top-left corner.
Sheldon LivingstonConsultantAuthor Commented:
Here my code below...

CGRect theFrame = thePie.frame;
        theSpin = theSpin + 0.01745333333333;
        thePie.transform = CGAffineTransformMakeRotation(theSpin);
        theFrame.size.width = 250 * incrementStep;
        theFrame.size.height = 250 * incrementStep;
        incrementStep += incrementValue;
        thePie.frame = theFrame; =;

Open in new window

Have you tried what I showed above?
Sheldon LivingstonConsultantAuthor Commented:
No... was hoping you could see my code and make a simple tweak suggestion.  
With my code it seems to rotate like a pinwheel but also front to back.  It doesn't rotate on a plane, but rather in space.
Sheldon LivingstonConsultantAuthor Commented:
No can do... don't understand when to put code in .h file or .m file... yep... I'm stumbling along here.

So it appears that you declare an UIView, setFrame (whatever that means) and don't set clips to bounds.

Then you made an UIImageView and put a blue square in it, added it to the rotating UIView and then released the content view (guess you can do that once you added it to the UIView).

Then you added the rotating UIView to a parent container and instructed it to rotate 360 degree's in a seconds time.

You also make it seem that you can not rotate an imageview... only a view.

Rotating imageviews work - it is just that we needed to position a blank UIView in the middle of where you had your real view.  From there, we can rotate that blank UIView, and since we positioned the center of our new image at the top left corner of the UIView, it appears as if it is rotating from the middle.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.