views:

136

answers:

1

Hi, all!

In my application, I want to find out wheather an image is over another image, and if it is then I have to swap that image with other i.e. bring the below rendered image on the front. For this, I'm writing below code :

 CGRect rect_1=CGRectMake(rect1X, rect1Y, rectW, rectH);
 CGRect rect_2=CGRectMake(rect2X, rect2Y, rectW2, rectH2);
 if(CGRectIntersectsRect(rect_1, rect_2))
 {
    [ravanImage bringSubviewToFront:ravanImage1];
 }

in which if ravanImage is over ravanImage1 then ravanImage1 should come above. But this' not working. Whereas it's detecting wheather a rect is over other or not correctly, it's not bringing the view to front.

Can anybody help me? Thanx in advance.

+1  A: 

Create UIImageView objects out of your ravanImage and ravanImage1 and add them to a holder view - A dummy UIView instance. Add this holder view as the subview of window or another view, whichever applicable.

Next, use the bringSubviewToFront api on the holder view if you want to bring ravanImage1 front.

.
.
.
[holderView addSubview: ravanImage];
[holderView addSubview: ravanImage1];
.
.
.
if (...your_condition...)
{
    [holderView bringSubviewToFront: ravanImage1];
}

I am perplexed by the name "ravanImage" though! What does it mean, Ram Ravan?

Raj
He he.. Thanx Raj, it helped..!
neha