Reputation: 29
I am moving most of UIImageViews on view and keeping an UIImageview fixed. Everything is happening fine but problem is when moving imageviews are containing or intersecting the fixed imageview, they are just moving from under fixed imageview. How to make UIImageviews to move over the fixed imageview. Please Find the function StartMoving code which makes UIImageviews to move in screen and called on buttonClick event.
In code...
CGPoint pos1,Pos2,pos3;
UIImageView *ball1,*ball2,*ball3,*fixedball;
-(void)StartMoving
{
pos1=CGPointMake(5.0, 5.0);
pos2=CGPointMake(5.0, 8.0);
pos3=CGPointMake(8.0, 5.0);
ball1.center=CGPointMake(ball1.center.x+pos1.x, ball1.center.y+pos1.y);
ball2.center=CGPointMake(ball2.center.x+pos2.x, ball2.center.y+pos2.y);
ball3.center=CGPointMake(ball3.center.x+pos3.x, ball3.center.y+pos3.y);
if(ball1.center.x>320||ball1.center.x<0)
pos1.x=-pos1.x;
if(ball1.center.y>480||ball1.center.y<0)
pos1.y=-pos1.y;
if(ball2.center.x>320||ball2.center.x<0)
pos2.x=-pos2.x;
if(ball2.center.y>480||ball2.center.y<0)
pos2.y=-pos2.y;
if(ball3.center.x>320||ball3.center.x<0)
pos3.x=-pos3.x;
if(ball3.center.y>480||ball3.center.y<0)
pos3.y=-pos3.y;
}
...and have added all moving and fixed imageviews in stroyboard. Thanks in advance
Upvotes: 1
Views: 68
Reputation: 8202
You need to bring that subview to the front of the other subviews:
UIView *viewContainingBalls; // most likely ball1.superview
[viewContainingBalls bringSubviewToFront:ball1];
Use this method to bring the other balls to the front as needed.
Or if you always want the fixed ball to be behind all the other balls you could just send this to the back:
UIView *viewContainingBalls; // most likely fixedball.superview
[viewContainingBalls sendSubviewToBack:fixedball];
There are other methods such as exchangeSubviewAtIndex:withSubviewAtIndex:
that also accomplish similar a thing.
Upvotes: 2