2012-08-22 49 views

回答

1

在自定义视图中,您可以覆盖touchesEnded方法。此示例代码可能有助于您的自定义视图命中测试问题。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

      if ([touches count] == 1) { 
       UITouch *touch = [touches anyObject]; 
       CGPoint point = [touch locationInView:custom_view]; 

       if (CGRectContainsPoint(custom_view.bounds, point)) { 
        //if touch hit to custom_view 
       }; 
      } 
      [super touchesEnded:touches withEvent:event]; 
     } 
+0

感谢您的支持:) – riyaz

1

其一,如果你知道这两个对象的框架,你可以使用CGRectIntersectsRect

if (CGRectIntersectsRect(topObjectsRect, bottomObjectsRect)) { 
     // 
    } 

此外,您可以得到被触摸的点,然后使用以下来检查该点是否在某个矩形中。

if (CGRectContainsPoint(CGRectMake(someX, someY, someWidth, someHeight), pointOfTouch)) 
    { 
     // 
    } 
+1

感谢您的回答:)pointOfTouch指的是什么? – riyaz

+0

@riyaz pointOfTouch指CGPoint。 –