0
我的主视图上有一堆UIView
。我已将touchesBegan,touchesMoved和touchesEnded功能添加到应用程序中。iOS - touchesmoved每个视图只有一次
移动时,该点处的视图会多次显示,除非触摸超出视图的CGRect
。我想是指每个视图,只有当移过视图,而不是被认为除非移出的CGRect,然后回到了曾经在这里是我的代码:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:self.view];
UIView *movedView = [self viewAtPoint:point];
if(movedView != nil)
{
NSLog(@"Touches Moved - %@",movedView.name);
}
}
-(UIView *) viewAtPoint:(CGPoint) point
{
CGRect touchRect = CGRectMake(point.x, point.y, 1.0, 1.0);
for(UIView *c in viewArray.views){
if(CGRectIntersectsRect(c.frame, touchRect)){
return c;
}
}
return nil;
}
所以NSLog
转储了同样的观点多次。我只想在移动视图时将其限制为一次,直到再次移出视图。
有什么建议吗?最后一个观点
有时也可以是相同的观点两次但这一举措必须超出视野范围,然后重新计为两次。所以,如果我跟踪最后一个视图,我无法连续两次获取相同的视图。 – peace4theapes 2012-07-20 19:19:20
是的,你可以,当你移动时,你只需检查它是否仍然在那个视图中,如果它不是,那么你将currentView重置为零,然后当它再次移回到原始视图时,它会注册为新的命中 – 2012-07-20 19:20:25