简体   繁体   English

如何在UITableViewCell上检测“长按”手势

[英]how do I detect a “long Tap” gesture on a UITableViewCell

In my app I'm displaying a table with different elements if a user taps on a tableviewcell a detailview gets pushed onto the navigationstack. 在我的应用程序中,我正在显示一个包含不同元素的表,如果用户点击tableviewcell,则会将详细视图推送到导航堆栈。 I now want to provide the user with abilty to "long tap" on a tableviewcell in order to pop up an alertview showing the user different options that can be applied on said tableviewcell (email information to a friend, print it out, add to bookmarks etc) 我现在想要在桌面单元上为用户提供“长按”的能力,以便弹出警报视图,向用户显示可以应用于所述tableviewcell的不同选项(向朋友发送电子邮件信息,打印出来,添加到书签)等等)

how do i implement a "long tap" gesture recognizer on a UITableViewCell?? 如何在UITableViewCell上实现“长按”手势识别器?

thanks for your help 谢谢你的帮助

Have you looked at UILongPressGestureRecognizer? 你看过UILongPressGestureRecognizer吗? See: http://developer.apple.com/library/ios/#documentation/uikit/reference/UILongPressGestureRecognizer_Class/Reference/Reference.html%23//apple_ref/occ/cl/UILongPressGestureRecognizer 请参阅: http//developer.apple.com/library/ios/#documentation/uikit/reference/UILongPressGestureRecognizer_Class/Reference/Reference.html%23//apple_ref/occ/cl/UILongPressGestureRecognizer

You might want to consider a swipe gesture as seen in the Twitter app instead, though: I don't think that a long tap on a table cell would be very intuitive to use or expected by the user. 您可能想要考虑在Twitter应用程序中看到的滑动手势,但是:我不认为长时间点击表格单元格会非常直观地使用或期望用户使用。 Just my 2 cents. 只需2美分。

  • Johannes 约翰内斯

on a touch down you would use a timer to fire off a method call in X number of seconds (how ever long you want the long touch to be). 在触地时你会使用一个计时器来在X秒内触发一个方法调用(你需要长时间的触摸)。 Then if they let go before that time you cancel the timer: 然后如果他们在那之前放开你取消计时器:

-(void) startSingleTouch:(UITouch*)touch
{
 tapTouch = touch;
 tapTimer = [[NSTimer scheduledTimerWithTimeInterval:tapDelay target:self selector:@selector(singleTapGestureSucceeded) userInfo:nil repeats:NO] retain];
}

-(void) cancelSingleTouch
{
 if(tapTimer)
 {
  [tapTimer invalidate];
  [tapTimer release];
 }

 tapTouch = nil;
 tapTimer = nil;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM