iphone - Xcode - UIImageView 在边缘停止

标签 iphone ios xcode uiimageview

我有一个 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/

相关文章:

iOS8 RSSI 和 Proximity 意外结果

iphone - Xcode Base 国际化不起作用

iphone - 一段时间后 NSTimer 在后台停止

ios - 如何在 Storyboard 中的按钮上实现这种布局?

ios - 这是 UITableViewCellAccessoryDe​​tailDisclosureButton 的正常行为吗

iPhone 开发 - 使用 NSPredicate 从 CoreData 检索最近添加的记录

iphone - 管理多个按下的 UIButton

ios - Xcode 5 缩进问题

iphone - UINavigationBar 控件,不拾取 self.title 或 self.navigationItem.title

ios - 无法从视频网址生成缩略图