Iphone 如何获得利润

Iphone 如何获得利润,iphone,objective-c,cocoa-touch,uitouch,Iphone,Objective C,Cocoa Touch,Uitouch,在我的应用程序中,我想移动红色矩形内的对象(使用下面的代码进行触摸),如何实现这一点 代码: UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:[touch view]]; if (insidethepaddle) { object1.center = CGPointMake(location.x, location.y - 50); } 只需使用CGRec

在我的应用程序中,我想移动红色矩形内的对象(使用下面的代码进行触摸),如何实现这一点

代码:

UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:[touch view]];
if (insidethepaddle) {
    object1.center = CGPointMake(location.x, location.y - 50);
}

只需使用
CGRectContainsPoint(CGRect rect,CGPoint point)
NSPointInRect(NSPoint aPoint,NSRect aRect)
测试中心是否仍在内部,否则只需不更新对象
center


指定的
CGRect
/
NSRect
表示红色矩形的框架。

请澄清您的问题,至少我不明白您想要实现什么。@Erik Aigner,我只想让对象在红色矩形中移动,换句话说,我需要限制坐标(x,y)我使用了你的代码CGRect red=CGRectMake(40,80,300,440);如果(InsideThePaile&&CGRectContainsPoint(红色,位置)){paile.center=CGPointMake(location.x,location.y-50)}它可以正常工作,但当我出现红色时,对象会释放csn我如何解决这个问题