【问题标题】:how to make margin如何做保证金
【发布时间】:2011-03-21 19:31:08
【问题描述】:

在我的应用程序中,我想在红色矩形内移动对象(使用下面的代码通过触摸)如何制作这个

代码:

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

【问题讨论】:

  • 请澄清您的问题,至少我无法理解您想要实现的目标。
  • @Erik Aigner,我只想让对象在红色矩形中移动,换句话说我需要限制对象的坐标(x,y)

标签: iphone objective-c cocoa-touch uitouch


【解决方案1】:

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

指定的CGRect/NSRect代表红色矩形的边框。

【讨论】:

  • 我用了你的代码 CGRect red = CGRectMake(40, 80, 300, 440); if (insidethepaddle && CGRectContainsPoint(red, location)) { paddle.center = CGPointMake(location.x, location.y - 50);它工作正常,但是当我走出红色时,对象释放 csn 我如何解决这个问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多