Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dusker

macrumors member
Original poster
May 31, 2009
41
0
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
 
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...
 
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...

:) 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
 ...
}
 
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?
 
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 ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.