我有一个 UIImageView 正在使用计时器向 View 的边缘移动,但它继续进行,我不知道如何在它到达边缘时立即停止 UIImageView!请帮忙? 这是我迄今为止尝试过的方法!
代码:
-(void)moveBack {
CGPoint manCenter = man.center;
if (manCenter.x > 480) {
manCenter.x = 480;
}
man.center = CGPointMake(man.center.x +5, man.center.y);
[self ifCollided];
}
最佳答案
当您执行 man.center.x + 5
时,它将超出 UIImage
框架。当您将其设置为 480 时,它应该是合适的。
-(void)moveBack {
man.center = CGPointMake(man.center.x + 5, man.center.y);
[self ifCollided];
if (man.center.x > 480) {
man.center = CGPointMake(480 , man.center.y);
}
}
关于iphone - Xcode - UIImageView 在边缘停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10062617/