我用点击手势识别器制作了一个可点击的视图,工作得很好.但我希望在触摸发生时突出显示视图,并在触摸结束时将其移除.
我试过这个:
- (IBAction)refresh:(UITapGestureRecognizer *)sender { if(self.currentStatus == NODATA){ if(sender.state == UIGestureRecognizerStateBegan){ NSLog(@"Began!"); [self.dashboardViewController.calendarContainer state:UIViewContainerStatusSELECTED]; } if (sender.state == UIGestureRecognizerStateEnded){ NSLog(@"%@",@"Ended"); [self.dashboardViewController.calendarContainer state:UIViewContainerStatusNORMAL]; } [self setState:REFRESHING data:nil]; } }
解决方法
UITapGestureRecognizer永远不会进入UIGestureRecognizerStateBegan状态.只有连续手势(例如滑动或捏合)才会使识别器从UIGestureRecognizerStatePossible变为UIGestureRecognizerStateBegan.离散手势(例如点按)将其识别器直接放入UIGestureRecognizerStateRecognized,即单击一下,直接进入UIGestureRecognizerStateEnded.
也就是说,也许你正在寻找一个UILongPressGestureRecognizer,这是一个连续的识别器,它将进入UIGestureRecognizerStateBegan,让你能够识别触摸的开始和结束?