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

Narcs

macrumors newbie
Original poster
Jan 19, 2012
10
0
I have a UIImageView called hitBox, and another image called mainSprite. So what I wanna do is when an IBAction is pressed, it will move hitBox to above mainSprite. I don't know if this is syntax but this is what i know moves things on the screen.

Code:
hitBox.center = CGPointMake(x coordinate, y coordinate);

I just want to replace x coordinate and y coordinate with something that will place it somewhere in relation mainSprite.

THANKS :)
 
Last edited by a moderator:
To move the hitBox above mainSprite, you just have to calculate the height of each, and divide by 2 if you want the hitBox to sit right on top of mainSprite. Use that new value for the y coordinate after subtracting it from the y value of mainSprite. To align the center of each, assign the x center point to the new center for hitBox.

If what you want is to cover mainSprite with hitBox, then you also have to change the place they in appear in their superview hierarchy. Look at the following methods in the UIView class.

Code:
bringSubviewToFront:
sendSubviewToBack:
exchangeSubviewAtIndex:withSubviewAtIndex:
insertSubview:aboveSubview:
insertSubview:belowSubview:
 
Last edited by a moderator:
I have a UIImageView called hitBox, and another image called mainSprite. So what I wanna do is when an IBAction is pressed, it will move hitBox to above mainSprite. I don't know if this is syntax but this is what i know moves things on the screen.

hitBox.center = CGPointMake(x coordinate, y coordinate);

I just want to replace x coordinate and y coordinate with something that will place it somewhere in relation mainSprite.

THANKS :)

Look at the NSView "convertPoint" and "convertRect" methods.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.