Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Rotate UIImageView in xcode

Posted on 2011-09-12
9
Medium Priority
?
1,842 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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
 
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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

916 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