I have a very simple app that has an UIImageView and an UIButton. Every time the user presses the button the image will move -44 in x direction and -41 in y direction. My question is: how can I set an "if statement" so that when the UIImageView reaches a certain point in the screen (maybe the end of the screen) it will regenerate at other point in the screen (maybe the beginning of the screen)?
Something like: if imageOne reaches x point and y point, then regenerate imageOne at x point and y point.
This my code:
file. h
{
IBOutlet UIImageView *ImageOne;
}
-(IBAction)Button:(id)sender;
file. m
-(IBAction)Button:(id)sender{
//ImageOne moving down the screen
[UIView animateWithDuration:0.1f
animations:^{
ImageOne.center = CGPointMake(ImageOne.center.x -44, ImageOne.center.y +41);
}];
What do i need to implement in my code?
Any help would be greatly appreciated!
Thank you in advance!
I don't think you need to use "animateWithDuration" for your purpose.
Let's say you have imageOne and you are moving it left in the x direction and when the image moves out of the screen, you want it to move back to the middle of the screen. Try this
-(IBAction)Button:(id)sender{
//reset image onto screen.
if(imageOne.center.x < 0){
imageOne.center = CGPointMake(200, imageOne.center.y);
}
//move image left
imageOne.center = CGPointMake(imageOne.center.x-44, imageOne.center.y);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.