uilongpressgesturerecogwomennizerr 什么时候触发

本周问答荣誉榜
本月问答荣誉榜
含有标签"UILongPressGestureRecognizer"的问题
我的程序里用UILongPressGestureRecognizer,但是如果直接点在view上不动,不会响应手势,只有稍微移动一下才会响应,请问有人遇到过这样的问题吗?应该怎么解决?
以下是我添加手势的代码
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressFrom:)];
&[pressView addGestureRecognizer:longPressRecognizer];
#define CellKey @"Cell"
在tableview的cellForRowAtIndexPath里添加的手势
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
& & [longPressGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];
& & [longPressGestureRecognizer setMinimumPressDuration:1.0f];
& & [longPressGestureRecognizer setValue:cell forKey:CellKey];
& & [cell addGestureRecognizer:longPressGestureRecognizer];
在[longPressGestureRecognizer&setValue:cell&forKey:CellKey];这句话报
'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Cell.'
今天刚刚发现给tableviewcell添加长按手势后,每次长按cell时,长按手势对应的方法会被执行两次&
代码如下 &就是这个longPressedAct函数 &每次都会执行两次 这个执行次数可以控制吗 有哪位朋友能解释一下&
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier];
& & cell.textLabel.text = @"hello world";
& & UILongPressGestureRecognizer *longPressed = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressedAct:)];
& & longPressed.minimumPressDuration = 1;
& & [cell.contentView addGestureRecognizer:longPressed];
-(void)longPressedAct:(id)sender{
//& & if (tabFlag == 0) {
//& & & & NSLog(@"12121");
//& & & & tabFlag = 1;
//& & } else {
//& & & & tabFlag = 0;
UILongPressGestureRecognizer *longPressGR =
[[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(handleLongPress:)];
longPressGR.minimumPressDuration = 0.2;
[cell addGestureRecognizer:longPressGR];//cell是tableview中的一行
[longPressGR release];
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer {
if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"longPress"
message:@"" delegate:self cancelButtonTitle:@"ok",otherButtonTitles:nil];
[alert show];
[alert release];
我是新手,现在是这么写的,在按住超过2秒之后,松开,会跳出alert
可是,我是希望做到,在一直按住cell,不离开的情况下,超过2秒时跳出alert
不知道哪位高人能教教我...手势 UILongPressGestureRecognizer 长按手势
UILongPressGestureRecognizer * longPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongpressGesture:)];
设置长按手势触发的时间
longPressGesture.minimumPressDuration = 1;
[redView addGestureRecognizer:longPressGesture];
[longPressGesture release];
长按手势 可能会触发两次
(开始接触 和
结束接触 )
所以 长按手势要判断状态
- (void)handleLongpressGesture :(UILongPressGestureRecognizer *)longPressGesture
当识别到长按手势时触发(长按时间到达之后触发)
if (UIGestureRecognizerStateBegan ==longPressGesture.state) {
longPressGesture.view.backgroundColor = [UIColor random];
> 本站内容系网友提交或本网编辑转载,其目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请及时与本网联系,我们将在第一时间删除内容!
UILongPressGestureRecognizer * longPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongpressGesture:)];设置手势触发的时间
longPressGesture.m ...
这篇文章主要介绍了Swift中实现点击.双击.捏.旋转.拖动.划动.长按手势的类和方法介绍,本文分别给出了各种手势的实现代码,需要的朋友可以参考下1.UITapGestureRecognizer 点击/双击手势 代码如下:var tapGesture = UITapGestureRecognizer(target: self, action: &h ...
这里我们为tableview添加手势 UILongPressGestureRecognizer *longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];
longPressGr.minimu ...
#import &RootViewController.h& #import &UIColor+MyUIColor.h& @interface RootViewController () @end @implementation RootViewController /* UITapGestureRecognizer是 ...
全局变量: @interface UIViewController () { NSIndexPath *_indexP } @end 1.首先添加手势: - (void)loadView { [super loadView]; self.view = kAppBg; self.view.backgroundColor = [UIColor white ...
前言:Android关于手势的操作提供两种形式:一种是针对用户手指在屏幕上划出的动作而进行移动的检测,这些手势的检测通过android提供的监听器来实现:另一种是用户手指在屏幕上滑动而形成一定的不规则的几何图形(即为多个持续触摸事件在屏幕形成特定的形状):本文主要是针对第二种手势的绘制原理进行浅析,我们姑且称它为输入法手势:
一. 输入法手势
手势识别器这个类 是一个抽象类 自己本身不实现什么具体功能 具体功能都是由其子类去完成的 下面就通过对图片的一下操作介绍一下 UIGestureRecognizer 这个类的常用方法 @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // 创建一个ima ...
Android开发之手势滑动(滑动手势监听)详解
在Android应用中,经常需要手势滑动操作,比如上下滑动,或左右方向滑动,处理手势滑动通常有两种方法:一种是单独实现setOnTouchListener监听器来,另一种是构建手势探测器 第一种方法,就是在要实现滑动的View中,实现OnTouchListener监听事件,然后判断KeyDonw和KeyU ...关于UITapGestureRecognize&和UILongPressGesture手势触发事件
两个手势很简单,但是总会遇到一些小得bug。在这里的一补充。
1.UITapGesture点击手势,会二次甚至多次触发事件:
例如:我们只是想实现点击,进入某一页面。但是实现出来之后会发现,我可能连续点击n多次,这时候就会出现:跳进页面n多次,这不是我们想要的!怎么办?
一个 enable属性就ok!
- (void)tapAction:(UITapGestureRecognizer *)tap{
& & tap.enabled =
if ([LoginController isLogin:self]) {
&&NSInteger num = 0;
& & post_event_block("roadimg.api.v1.my.gps",
"start_record",
@{@"tid":[NSNumber numberWithInteger:num]},
^(NSDictionary *argument) {
tap.enabled = YES;
& if ([argument[@"flag"]integerValue]
RecordingViewController *recordView = [[RecordingViewController alloc]init];
[self.navigationController
pushViewController:recordView animated:YES];
2.对于长按手势,我们可以控制长按的时间,但是作为用户的我们不会去计算长按了多久,如果界面没有反应会一直长按下去,甚至会造成和多次单击事件的效果一样,那么怎么处理呢?
我们可以通过手势的属性:state去判断
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress{
& if (longPress.state ==
UIGestureRecognizerStateBegan)
NSInteger num =
post_event_block("roadimg.api.v1.my.gps",
"start_record",
@{@"tid":[NSNumber numberWithInteger:num]},
RecordingViewController *recordView = [[RecordingViewController alloc]init];
[self.navigationController
pushViewController:recordView animated:YES];
非常好用的办法。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。IOS给tableview的cell平添长按手势执行两次(UILongPressGestureRecognizer) - 操作系统当前位置:& &&&IOS给tableview的cell平添长按手势执行两次(UILongPIOS给tableview的cell平添长按手势执行两次(UILongPressGestureRecognizer)&&网友分享于:&&浏览:0次IOS给tableview的cell添加长按手势执行两次(UILongPressGestureRecognizer)这里我们为tableview添加长按手势
UILongPressGestureRecognizer *longPressGr = [[UILongPressGestureRecognizer
alloc] initWithTarget:self
action:@selector(longPressAction:)];
& & longPressGr.minimumPressDuration =
& & longPressGr.numberOfTouchesRequired =
& & [_tableView addGestureRecognizer:longPressGr];
& & [longPressGr release];
这时我们会发现每次按住tableView并且松开的时候, longPressAction: 这个方法会执行2次
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
& & if (longPress.state ==
UIGestureRecognizerStateBegan) {
& & & & CGPoint point = [longPress
locationInView:_tableView];
& & & & NSIndexPath *indexPath = [_tableView
indexPathForRowAtPoint:point]; // 可以获取我们在哪个cell上长按
& & & & if (indexPath != nil) {
& & & & & & NSLog(@&%ld&, indexPath.row);
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 1234567891011 Copyright & &&版权所有-(void)initGR{
&&&&UILongPressGestureRecognizer&*longPressGR&=&[[UILongPressGestureRecognizer&alloc]&initWithTarget:self&action:@selector(handleLongPress:)];
&&&&longPressGR.minimumPressDuration&=&0.7;
&&&&[self&addGestureRecognizer:longPressGR];
-(void)handleLongPress:(UILongPressGestureRecognizer&*)recognize{
& 开源中国(OSChina.NET) |
开源中国社区(OSChina.net)是工信部
指定的官方社区

我要回帖

更多关于 gesturerecognizer 的文章

 

随机推荐