Rotate image

In xcode I have a UIImageView with an image.  When I rotate the image via CGAffineTransformMakeRotation the image not only rotates but the UIImageView changes height and width.
I wish to maintain the height and width.
Any thoughts?
Sheldon LivingstonConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jschristian44Commented:
it only does that because it doesn't need to keep the aspect ratio.  i am not familiar with the coding in apple at all, so just use a code that puts aspect ratio = 1 or something like that.  that will turn on aspect ration and it should be the right size without changing.  or maybe it's the other way, that aspect needs to be turned off, i am not really sure, try them both.
0
Sheldon LivingstonConsultantAuthor Commented:
The line of code that I am using is:
whichAntt.transform = CGAffineTransformMakeRotation(-M_PI / 4);
This has nothing to do with Portrait or Landscape mode... just want to rotate a picture.
0
jschristian44Commented:
then i suggest using a code to put in the amount of pixels you want it after the rotate code.  like 50 pixels high and 30 pixels wide.  whatever you want to keep it.  simple as that.
0
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

mad_macCommented:
try setting the autoresizingMask of your UIImageView to  UIViewAutoresizingNone which suppresses the auto resizing of a view.
0
Sheldon LivingstonConsultantAuthor Commented:
That didn't work mad_mac:.  Inside of this UIImageView I have a UIImage.  How would I just rotate a UIImage instead of the view?
0
mad_macCommented:
you cannot rotate the UIImage directly in that way.

i think what you will need to do is create a new CALayer and add this to the layer tree and rotate the CALayer not the entire view...  a code fragment below which may help

CALayer *imageLayer = [CALayer layer];

imageLayer.position=CGPointMake(50.0f,50.0f);
imageLayer.bounds=CGRectMake(0.0f,0.0f,100.0f,100.0f);
 
imageLayer.contents=[[UIImage imageNamed=@"YOURIMAGE"] CGImage];

[view.layer addSublayer:imageLayer];

imageLayer. affineTransform = CGAffineTransformMakeRotation(-M_PI / 4);

Open in new window


hope this helps, you may need to check the code as i have done this blind.  not in front of a development machine at the moment.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sheldon LivingstonConsultantAuthor Commented:
I wonder if I am better off just changing the image...   I basically rotate in 8 points (N, NW, W, etc).  Do you think swapping images would be better than rotating?
0
mad_macCommented:
that would depend on what you are trying to achieve here, if you are looking for a smooth animated rotation of the image to one of 8 positions then switching the image will not work.  if it simply jups to one of 8 positions then switching the image will work.

I would give the layer idea a go first
0
Sheldon LivingstonConsultantAuthor Commented:
I'd like to try the CALayer approach...  

I currently have a UIImageView that has, or contains, a UIImage.

Does the CALayer sit on top of the view and contain the image?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Swift Programming

From novice to tech pro — start learning today.