Moving many UIImageViews at once

Discussion in 'iOS Programming' started by dusker, Sep 29, 2009.

  1. dusker macrumors member

    Joined:
    May 31, 2009
    #1
    Hello,
    i have a following problem: I have several UIImageViews in my app. I'd like to be able to move them in a loop. My question is how to modify them one by one without having to do the same thing for every instance of the UIImageView?
    I tried to put them all into a NSMutableArray. Now i can go through the entire array with a simple FOR loop. But how to modify each UIImageView in the array?
    Code for moving the UIImageView looks like this:
    Code:
    CGRect f = imageView.frame;
    f.origin.x += xDelta;
    f.origin.y += yDelta;
    imageView.frame = f;
    Would anyone be so helpful and show me how the code inside the for loop would look like?
    thanks
    peter
     
  2. drivefast macrumors regular

    Joined:
    Mar 13, 2008
    #2
    so whats wrong with this:

    Code:
    for (UIImageView *imageView in myArrayOfImageViews) {
       CGRect f = imageView.frame;
       f.origin.x += xDelta;
       f.origin.y += yDelta;
       imageView.frame = f;
    }
    
    although if i were you, i would create a large UIView, add all the image views to it as subviews, then only move the big view by xDelta and yDelta...
     
  3. dusker thread starter macrumors member

    Joined:
    May 31, 2009
    #3
    :) thanks for answer but the code that you wrote doesn't really make sense. My question was rather how to reference each uiimageview from the loop and modify it. something like:
    Code:
    for(int i = 0; i < [array count]; i++){
     CGRect f = [array ObjectAtIndex:i].frame //but this won't work
     ...
    }
    
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    His code makes perfect sense. What you wrote does not. You said you have an array of NSImageViews. So why do you think that you can use those as CGRect?
     
  5. dusker thread starter macrumors member

    Joined:
    May 31, 2009
    #5
    Oh My Gosh! I'm so sorry guys, of course that code makes perfect sense. I don't know what was i thinking... Being up for more than 24hrs makes my brain malfunction :)
    sorry ;)
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Can we make it a sticky in the iPhone Programming forum to not post if you are sleep-deprived? This is happening too much lately. :D
     

Share This Page