user3121709
user3121709

Reputation: 11

CGRectIntersectsRect not detecting the intersected view

I have two scrollviews one at left and other at right side.

In left scrollview, i have placed list of uiviews with label on it, for naming them.

In right scrollview, i have placed list of scrollviews, in each scroll view i have placed list of uiviews with label on it for naming them.

I am using CGRectIntersectsRect for detecting the intersection of one of the uiview from left scrollview with any of the uiview in right scrollview using drag and drop.

My problem is that CGRectIntersectsRect is not detecting the intersected view.

I am using uinavigationcontroller.

I have used OBDragDropTest project which i got in google search. In that i am making changes.

My code is below,

-(void) handleDropAnimationForOvum:(OBOvum*)ovum withDragView:(UIView*)dragView dragDropManager:(OBDragDropManager*)dragDropManager
{
  UIView *itemView = nil;


  if ([ovum.dataObject isKindOfClass:[NSNumber class]])
  {

       itemView = [self.view viewWithTag:[ovum.dataObject integerValue]];



      [viewsAry removeAllObjects];

      [viewsAry addObjectsFromArray:unAssignedViewContents];

      [viewsAry addObjectsFromArray:removeViewContents];

      [viewsAry addObjectsFromArray:repairViewContents];

      [viewsAry addObjectsFromArray:paintViewContents];

      [viewsAry addObjectsFromArray:refitViewContents];

      [viewsAry addObjectsFromArray:detailViewContents];

      [viewsAry addObjectsFromArray:completedViewContents];


      NSArray *subViewsInView=[NSArray arrayWithArray:viewsAry];






      for(UIView *theView in subViewsInView)
      {

          if (![itemView isEqual:theView])
          {

              if(CGRectIntersectsRect(theView.frame, ovum.dragView.frame))
              {
                  NSLog(@"view Tag  =  %d",theView.tag);
              }

          }

      }



  }

I have setUserInteractionEnabled = True for all the views and scrollviews.

Kindly give the solution for this problem.

Upvotes: 0

Views: 198

Answers (1)

user3121709
user3121709

Reputation: 11

Instead of the below code

if (![itemView isEqual:theView])
{
    if(CGRectIntersectsRect(theView.frame, ovum.dragView.frame))
    {
         NSLog(@"view Tag  =  %d",theView.tag);
    }
}

I used

if (![itemView isEqual:theView])
{
    CGPoint point = [theView convertPoint:dragView.center fromView:dragView.superview];
    if([theView pointInside:point withEvent:nil])
    {
        NSLog(@"view Tag  =  %d",theView.tag);
    }
}

and the detection of intersection of the subviews are done. Now i can get the receiver's tag no.

Upvotes: 1

Related Questions