【问题标题】:CGRectIntersectsRect not detecting the intersected viewCGRectIntersectsRect 未检测到相交视图
【发布时间】:2013-12-20 06:42:04
【问题描述】:

我有两个滚动视图,一个在左侧,另一个在右侧。

在左侧滚动视图中,我放置了带有标签的 uiviews 列表,用于命名它们。

在右滚动视图中,我放置了滚动视图列表,在每个滚动视图中,我放置了带有标签的 uiview 列表,用于命名它们。

我正在使用 CGRectIntersectsRect 来检测左侧滚动视图中的一个 uiview 与右侧滚动视图中的任何 uiview 的交集。

我的问题是 CGRectIntersectsRect 没有检测到相交的视图。

我正在使用 uinavigationcontroller。

我使用了在谷歌搜索中获得的 OBDragDropTest 项目。我正在做出改变。

我的代码如下,

-(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);
              }

          }

      }



  }

我为所有视图和滚动视图设置了 setUserInteractionEnabled = True。

请给出这个问题的解决方案。

【问题讨论】:

  • 请发布您的代码。
  • 必须显示代码。你用的是什么坐标系?

标签: objective-c uiview uiscrollview


【解决方案1】:

代替下面的代码

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

我用过

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);
    }
}

并完成子视图交集的检测。现在我可以得到接收者的标签号了。

【讨论】:

    猜你喜欢
    • 2011-10-17
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多