Note that there are some explanatory texts on larger screens.

plurals
  1. PONested UIView inside UIView collision detection and Touch forwarding
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/yPZt7.png" alt="problemStatement"></p> <p>Hi Guys,</p> <p>I am working on Drag and Drop for iPad. My problem is as under:</p> <p>I have created a custom view names ShapeView (see left on my image). I am creating instances of ShapeView in ShapeViewController (right side of the image). There is a placeholder in ShapeViewController (see the yellow triangle).</p> <p>I need to drop the shapeView objects on the placeholder which is in the ShapeViewController. For which the following code works fine:</p> <pre><code>-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if ([touch.view class] == [ShapeMatchView class]) { ShapeMatchView *currentShapeView = (ShapeMatchView *)touch.view; if (CGRectIntersectsRect(theBigImageView.frame, touch.view.frame)) { } } } </code></pre> <p>But I need to ensure that the ShapeView object is exactly inside the triangle. To ensure that I have added view points (UIViews) (see 1,2,3,4 on ShapeView object).</p> <p>I have one method in ShapeView to check the collision:</p> <pre><code>-(BOOL)hasHitTestDoneWithObject:(UIImageView *)object { BOOL retval = NO; if (CGRectIntersectsRect(topLeft.frame,object.frame) &amp;&amp; CGRectIntersectsRect(topRight.frame, object.frame) &amp;&amp; CGRectIntersectsRect(bottomLeft.frame, object.frame) &amp;&amp; CGRectIntersectsRect(bottomRight.frame, object.frame)) { retval = YES; } return retval; } </code></pre> <p>In ShapeViewController:</p> <pre><code>-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; if ([touch.view class] == [ShapeMatchView class]) { ShapeMatchView *currentShapeView = (ShapeMatchView *)touch.view; if ([currentShapeView hasHitTestDoneWithObject:theBigImageView]) { // Never comes here } } } </code></pre> <p>Where I am doing wrong?</p> <p>Please guide. Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload