2013-05-15 41 views
0

在我的应用程序中,我将多个小视图连接在一起形成一个大画布。我正确地为每个视图分别开始/移动/结束事件。我现在想要的是,如果我触摸view1并将手指从view1拖到view2的范围内,但不想抬起手指,我想让view2以某种方式得到一个通知,即我现在处于该视图中,即view2 。谢谢。从iOS SDK中获取手指滑动的当前视图

+1

在包含较小视图的视图上使用“UISwipeGestureRecognizer”可能会更好。在大视图上处理滑动事件时,可以将消息发送到关联的较小视图。 – rmaddy

+0

感谢您的指导。让我尝试一下。 – iAmd

回答

1

我能用touchesMoved方法做到这一点。代码如下:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
[super touchesMoved:touches withEvent:event]; 
CGPoint nowPoint = [touches.anyObject locationInView:self.view]; 
NSLog(@"%f, %f", nowPoint.x, nowPoint.y); 

NSArray *viewsToCheck = [self.view subviews]; 
for (UIView *v in viewsToCheck) 
{ 
    if ([v isKindOfClass:[CharacterTile class]]) 
    { 
     if (CGRectContainsPoint(v.frame, nowPoint)) 
     { 
      CharacterTile *ctTemp = (CharacterTile *)v; 
      //perform your work with the subview. 
     } 
    } 
} 
} 

其中CharacterTile是在self.view上添加的子视图。 CGRectContainsPoint指示用户触摸的点是否在视图内。