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

ozzieing

macrumors newbie
Original poster
Jun 24, 2009
6
0
I have a group of objects (UIImageViews) in an array. I want to arrange them by yvalues. The greater the y value, the smaller the number in the array. So the one at the top of the page will be the first in the array and the one at the bottom is the last in the array. They move around so every second or so the array will have to be re-arranged.

I have attempted to do this using NSSortDesciptors but the only way I can add a key to a UIImageView is to add .layer to the end but I can't add .layer to the array when I'm rearranging it so I get an error.

Does anyone have any idea how I could do this? Any help would be greatly appreciated.

Cheers,
Ozzie
 
You could subclass UIImageView or create a category method that returns this value. Something like:
Code:
- (CGFloat)yValue { return [self frame].origin.y; }
Then use "yValue" as the sort key.
 
You could subclass UIImageView or create a category method that returns this value. Something like:
Code:
- (CGFloat)yValue { return [self frame].origin.y; }
Then use "yValue" as the sort key.
Thank you so much! Sorted and now my app will be done.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.