Mirror, flip, inverse, invert, stop drop and roll

January 11, 2009 · Posted in dev 

Not having much to compare it to, I can’t honestly say how well the developer documentation stacks up against those available on other platforms. It certainly serves me well enough, and is worlds apart from what came with MPW. The day that MPW finally started working was a small miracle; this was before Google had an answer to just about everything (great instructional video too), and most libraries assumed you were using CodeWarrior anyway. At any rate, the reason for today’s post: for everything not spelled out by the developer docs, there’s Google.

After spending a good hour trying to trackdown a [UIImage reverse] method (there is none), I’ve boiled it down to a working block of code. Best of all, it’s short! So here’s to you, Googlers, I’m putting it on the internet in hopes that another dev finds it useful. The following snippet will horizontally reverse/flip/mirror a UIImageView:

UIImageView *myView = [[UIImageView alloc] initWithImage:myImage];
myView.transform = CGAffineTransformIdentity;
myView.transform = CGAffineTransformMakeScale(-1.0, 1.0);

That’s it. To flip it back:

myView.transform = CGAffineTransformIdentity;

Not so scary anymore! So what’s going on here? Get your answers from a more authoritative source. It’s a good read about a powerful property, and highly recommended for anyone who doesn’t want to create two or ten different versions of the same image at different rotations.

Comments

2 Responses to “Mirror, flip, inverse, invert, stop drop and roll”

  1. Naren on January 22nd, 2009 6:23 am

    Hi,
    I am trying to rotate my image view upto some radians depends on the fingers touch, i m getting angle by
    atan2(diffX,diffY), that is difference between old x , pos and y pos,
    then
    CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
    myImageView.transform = transform;

    no error nothing, it compile well runs well but image is still there only,
    not getting any rotation. can you help me where i m going wrong.
    thanks a lot

  2. byron on January 22nd, 2009 7:14 pm

    I haven’t attempted any rotations yet, so instead of providing bad advice I’m going to pass on a link to some code snippets which may have an answer. Standford is hosting lecture notes and example code for their iPhone Application Programming course. Lecture 15 features rotation examples and will hopefully have what you’re looking for. Best of luck!

Leave a Reply