CGAffineTransform

Discussion in 'iOS Programming' started by Duke Leto, Jan 29, 2009.

  1. Duke Leto macrumors regular

    Joined:
    Mar 17, 2008
    #1
    I am making an arrow that resizes itself and rotates so that it can point from one point to the user's finger. I have attempted this with CGAffineTransforms, but it seems that when I rotate or scale, the arrow also gets translated. I am trying to figure out a way to offset the translation. Any advice on an easier solution to the problem or an other help with transforms will be greatly appreciated.
     
  2. Delirium39 macrumors regular

    Joined:
    May 19, 2008
    #2
    I'm not sure I fully understand what is happening vs. what your goal is. Could you give more detail, and perhaps the transformation calls you're making?
     
  3. Duke Leto thread starter macrumors regular

    Joined:
    Mar 17, 2008
    #3
    Okay. I have a physics simulation. In order for a user to create an initial velocity for an object, he would touch that object and drag out an arrow. I make a CGAffineTransform, then rotated it to the correct angle, then scaled it to meet the finger. However, the arrow gets skewed and translated. I think the problem may be with my initialization of the arrow's frame, but to be honest, I have never done anything like this before.
     
  4. CommanderData macrumors regular

    Joined:
    Dec 1, 2007
    #4
    I guess it might depend on what's containing that arrow. I do some rotations of a CALayer (which is sized to fit it's view, in turn sized to take up most of the screen). When I rotate the layer, it rotates around the *upper left* corner. which means once I've rotated right 90 degrees the image is completely off the screen to the left. In my case I needed to translate it after rotation in order to re center the image in the view.

    You also need to be careful applying transforms, order does matter a lot. In your description for example I think you'd want to *scale* the image first, then rotate (to avoid additional skew you're seeing by scaling second). Finally, you'll probably have to translate it to get the tail of your arrow back to where you want it (center of screen, or where ever you wanted the arrow's origin).
     
  5. Delirium39 macrumors regular

    Joined:
    May 19, 2008
    #5
    It may be easier to scale first, and then rotate. Choosing the correct translation point is key. If you had a picture of your desired before and after, I'd probably be able to give a better answer. But generally, choose a point for the transform to work around, and then do a transform. Then, reposition the point based on the next transform you need to do.
     

Share This Page