Xcode - UIImageView停在边缘

时间:2012-04-08 11:57:46

标签: iphone ios xcode uiimageview

我有一个UIImageView被一个计时器移动到视图的边缘但它继续进行,我不知道如何在它碰到边缘时立即停止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];
}

2 个答案:

答案 0 :(得分:2)

当您执行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);
    }
}

答案 1 :(得分:0)

-(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);
    }
}