Solved

Rotate UIImageView in xcode

Posted on 2011-09-12
9
1,758 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:classnet
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:SpeedyApocalypse
ID: 36530613
So are you looking to rotate the image around a center point?  Could you post what you have now?
0
 

Author Comment

by:classnet
ID: 36530732
From the center point... like a pinwheel
0
 
LVL 13

Expert Comment

by:SpeedyApocalypse
ID: 36530897
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.
0
 

Author Comment

by:classnet
ID: 36531084
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;
        thePie.center = theScreen.center;

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Expert Comment

by:SpeedyApocalypse
ID: 36531087
Have you tried what I showed above?
0
 

Author Comment

by:classnet
ID: 36531153
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.
0
 
LVL 13

Accepted Solution

by:
SpeedyApocalypse earned 500 total points
ID: 36531179
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.
0
 

Author Comment

by:classnet
ID: 36531297
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.

0
 
LVL 13

Expert Comment

by:SpeedyApocalypse
ID: 36531449
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C# Error - Add Failed 12 78
Path to Python 9 110
iPhone. Contacts icon not on home screen 3 53
Advice on Xojo as a development tool over VB. 4 40
Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now