阻止物体离开屏幕

时间:2013-04-12 11:51:45

标签: iphone ios objective-c

我写了这段代码来阻止UIImage离开屏幕,但这只适用于左侧。我怎样才能让这些代码在右侧工作?

请注意,UIImage由加速度计控制:

CGFloat leftOfWorld = 0.0f;
CGFloat minCenterX = leftOfWorld + (person.bounds.size.width / 2.0f);
person.center = CGPointMake(MAX(minCenterX, person.center.x), person.center.y);

1 个答案:

答案 0 :(得分:0)

你走了:

CGFloat maxCenterX = self.view.frame.size.width - (person.bounds.size.width / 2.0f);
person.center = CGPointMake(MIN(maxCenterX, person.center.x), person.center.y);