I'm trying to make it so when you touch the image it moves to a random spot, but I now realize I need it to stay with in a set space so I can add things like a score counter. The problem I'm having is that I have no idea how to do this so any help is appreciated.
My Code:
-(IBAction)hideImage {
CGFloat xRange = self.view.bounds.size.width - Image.bounds.size.width;
CGFloat yRange = self.view.bounds.size.height - Image.bounds.size.height;
CGFloat minX = self.view.center.x - (xRange / 2);
CGFloat minY = self.view.center.y - (yRange / 2);
int randomX = (arc4random() % (int)floorf(xRange)) + minX;
int randomY = (arc4random() % (int)floorf(yRange)) + minY;
Image.center = CGPointMake(randomX, randomY);
}
Thank you.
You could use a UIView that has the frame that you want. Then add the UIImageView to the UIView and set:
So: