Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have two NSMutableArrays with UIImageViews in it. I am wondering how to check if the frames of the UIImageViews are equal to the frames of the other array in Objective-C. Is there a function for this?

share|improve this question
There is no built-in method that does exactly what you're asking for. What have you tried, and what part are you stuck on? Is it comparing CGRects, or iterating through each array, or what? Are the corresponding views in the same order in each array, or might they be different? – Kurt Revis Jul 11 at 16:10
they are in the same order in each array. I tried this [array1 isEqualToArray:array2] in an if statement. But I found that some properties of the arrays are different from each other . – Steven Jul 11 at 16:14

1 Answer

up vote 0 down vote accepted

Assuming arrays are the same length and are called array1 and array2.

__block BOOL equal = YES;
[array1 enumerateObjectsUsingBlock:^(UIImageView *imageView, NSUInteger idx, BOOL *stop) {
    UIImageView *otherImageView = array2[idx];
    if (!CGRectEqualToRect(imageView.frame, otherImageView.frame))
    {
        equal = NO;
        *stop = YES;
    }
}];

if (equal) {
    // do stuff
}
share|improve this answer
Could you please explain what you are doing here? – Steven Jul 11 at 18:38
It iterates through every UIImageView in one array, finds the corresponding UIImageView from another array, and checks if their frames are equal. After the block has executed, we have a BOOL called equal that we can use in an if statement. – Ross Penman Jul 11 at 19:32
Thanks for your help! – Steven Jul 12 at 7:50
The only problem is that I use a NSTimer to check if the frames are equal to each other. – Steven Jul 12 at 14:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.