标签: uitapgesturerecognizer

同一UITapGestureRecogniser的多个UILabel点击不起作用

我正在尝试将相同的UITapGestureRecognizer添加到多个视图中

  var tapGesture = UITapGestureRecognizer(target: self, action: "selectOptionsForRating:")
        tapGesture.numberOfTapsRequired = 1

        serviceLbl.addGestureRecognizer(tapGesture)
        pickUpTimeLbl.addGestureRecognizer(tapGesture)
        drivingLbl.addGestureRecognizer(tapGesture)
        communicateLbl.addGestureRecognizer(tapGesture)
        bikeConditionLbl.addGestureRecognizer(tapGesture)
        dropOffLbl.addGestureRecognizer(tapGesture)

        serviceLbl.tag = Service
        pickUpTimeLbl.tag = PickUpTime
        drivingLbl.tag = Driving
        communicateLbl.tag = Communicate
        bikeConditionLbl.tag = BikeCondition
        dropOffLbl.tag = DropOff


    }

    func selectOptionsForRating(tapsender:UITapGestureRecognizer){

        var sender = tapsender.view

        if sender!.tag == Service {
             println("tap gesture is working fine ")

        }else if sender!.tag == PickUpTime {
            println("tap gesture is working fine ")

        }else if sender!.tag == Driving {
            println("tap gesture is working fine ")

        }else if sender!.tag …
Run Code Online (Sandbox Code Playgroud)

uilabel ios uitapgesturerecognizer swift

2
推荐指数
1
解决办法
2311
查看次数

如何防止子视图上的点击触发父视图上的 UITapGestureRecognizer?

我向视图添加了一个点击识别器:

   UITapGestureRecognizer* tgr = [[UITapGestureRecognizer alloc]
      initWithTarget:self action:@selector( onTap )];
   [view addGestureRecognizer: tgr];
Run Code Online (Sandbox Code Playgroud)

问题在于点击view触发器的子视图onTap。我该如何防止这种情况发生?

objective-c ios uitapgesturerecognizer

2
推荐指数
1
解决办法
1804
查看次数

如何以编程方式触发 UIView 的点击手势识别器

我想将点击gesture识别器附加到 anUIView并以编程方式触发它。我成功地找到了一种方法来找到UIView. 但现在我不知道如何以编程方式触发它。我正在开发应用程序crawler。所以,如果我有一个视图控制器的源代码,然后,我的履带就会开始检索发现所有subviewsViewController。此外,爬虫会发现gesture附加到subviews. 并触发点击gesture

注意:我知道如何将手势识别器附加到UIView并触发它。但就我而言,我想自动化应用程序的点击过程。考虑一下我想在运行时找到点击手势识别器UIView并触发它。

objective-c gesture-recognition uiview ios uitapgesturerecognizer

2
推荐指数
1
解决办法
5773
查看次数

UITableViewCell GestureReognizer的性能问题

我在UITableViewCells中添加了单击和双击手势识别器.但是在滚动表格几次之后,在我的滑动手势结束以滚动表格和滚动动画的开始之间会出现越来越长的暂停.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"tableViewCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
    singleTap.numberOfTapsRequired = 1;
    singleTap.numberOfTouchesRequired = 1;
    [cell addGestureRecognizer:singleTap];

    UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
    doubleTap.numberOfTapsRequired = 2;
    doubleTap.numberOfTouchesRequired = 1;
    [singleTap requireGestureRecognizerToFail:doubleTap];
    [cell addGestureRecognizer:doubleTap];

    if (tableView == self.searchDisplayController.searchResultsTableView) {
        // search results
    }
    else {
        // normal table
    }

    return cell;
} …
Run Code Online (Sandbox Code Playgroud)

uitableview ios uitapgesturerecognizer

1
推荐指数
1
解决办法
2104
查看次数

requireGestureRecognizerToFail不起作用

我正在使用两个不同的TapGestureRecognizer来处理屏幕上的单击和双击.这是代码:

UITapGestureRecognizer *tapGR =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
    [tapGR setDelegate:self];
    [tapGR setNumberOfTapsRequired:1];
    [self addGestureRecognizer:tapGR];


    UITapGestureRecognizer *doubleTapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTap:)];
    [doubleTapGR setNumberOfTouchesRequired:2];
    [self addGestureRecognizer:doubleTapGR];

    [tapGR requireGestureRecognizerToFail : doubleTapGR];

    [tapGR release];
    [doubleTapGR release];
Run Code Online (Sandbox Code Playgroud)

即使我指定了[tapGR requireGestureRecognizerToFail:doubleTapGR],也会执行"handleTap"选择器.哪里出错了?

iphone objective-c ipad ios uitapgesturerecognizer

1
推荐指数
1
解决办法
3604
查看次数

使用Tap Gesture识别器传递参数

之前曾以某种形式提出过这个问题,但我找不到适合我情况的答案.

简而言之:我正在为我的应用程序构建一个库模块.它由几个部分组成,每个部分都有许多缩略图.基本原则是图像查看器模块基于用户所在的部分以及他或她所使用的缩略图来模态地呈现和呈现.似乎很简单; 我需要的是在初始化图像查看器时传递两个int变量(一个用于剖面,一个用于图像),并且一切都是hunky-dory.

问题是UITapGestureRecognizer无法直接调用方法.它使用选择器,通过它我无法传递参数,更不用说两个了.我要找的是这样的:

[thumbnail004 setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap004 = [[UITapGestureRecognizer alloc] 
                       initWithTarget:self
                       action:@selector(imageTappedWithSectionNumber:6
                                                      andImageNumber:4)];
[thumbnail004 addGestureRecognizer:tap004];
Run Code Online (Sandbox Code Playgroud)

有没有办法在使用UITapGestureRecognizer时直接使用参数调用方法?

如果没有,解决这个问题的一个明显方法是为每个图像点击创建单独的方法,如:

- (void) image1_1Tapped { 
  // View initialization by passing 1 and 1
  }
- (void) image1_2Tapped { 
  // View initialization by passing 1 and 2
  }
And so on...
Run Code Online (Sandbox Code Playgroud)

这是可能的,因为图像库不是动态的,但是,它将是世界上最丑陋的代码,我想不惜一切代价避免使用它.

必须有一个方法来做一个干净优雅的代码...!

进一步参考:1.我不使用IB; 我以编程方式做所有事情.传递一个论点是不够的; 我真的需要通过两个.

iphone argument-passing ios uitapgesturerecognizer

1
推荐指数
1
解决办法
3942
查看次数

iOS"ViewController"没有可见的@interface声明选择器addGestureRecognizer错误

我正在尝试将手势识别器添加到主视图中,但我收到此错误:

"ViewController"没有可见的@interface声明选择器addGestureRecognizer错误

在这条线上:

 [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self.view action:@selector(isTapped:)]];
Run Code Online (Sandbox Code Playgroud)

你们中的任何人都知道错误的原因或如何解决这个错误?

objective-c ios uitapgesturerecognizer

1
推荐指数
1
解决办法
3322
查看次数

如何检测UICollectionView上的触摸?

我想在屏幕上有手指时禁用UICollectionViewController的自动旋转,就像iPhone照片应用程序那样.

怎么做?

  • 如果使用轻击手势,如何区分不同的触摸状态?(状态应该是touching,即使在手指移动之后.)
  • 如果使用touchBegan:withEvent:,在哪里放置该代码?(命中视图可以是UICollectionView的任何子视图.)

touch ios uitapgesturerecognizer uicollectionview

1
推荐指数
1
解决办法
5407
查看次数

用于暂停/播放按钮的UITapGestureRecognizer和tvOS遥控器

当用户点击Apple TV遥控器上的暂停/播放按钮时,我正在尝试创建一个动作.我查看了文档,但Apple推荐的代码不起作用.这是我的代码如下.有人可以告诉我我做错了什么吗?需要考虑的事项:我正在使用AVPlayerMovieController并且我的代码中确实有另一个手势识别器,但是它是一个轻扫手势并且这个方法被调用,而不是暂停/播放.有人可以帮忙吗?

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];  
    tap.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypePlayPause]];  
    [self.view addGestureRecognizer:tap];
Run Code Online (Sandbox Code Playgroud)

谢谢

objective-c apple-tv uitapgesturerecognizer tvos

1
推荐指数
1
解决办法
4058
查看次数

在圆形视图上的手势识别器

在我的集合视图的每个单元格中都是一个圆形的UIView.这是通过创建UIView我调用的自定义子类CircleViewlayer.cornerRadius = self.frame.size.width/2在子类中设置来实现的.awakeFromNib()

我想为每个CircleView添加一个手势识别器.我在集合视图中做了这个cellForItemAtIndexPath:

let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tap(_:)))
cell.circleView.addGestureRecognizer(gestureRecognizer)
Run Code Online (Sandbox Code Playgroud)

问题是,只要在原始方形UIView的边界内的任何地方发生敲击,就会调用手势识别器.我想只识别圆圈内出现的水龙头.

我试图通过以下方式解决此问题:

在CircleView的awakeFromNib()我设置self.clipsToBounds = true(没有效果)

也在CircleView的awakeFromNib()我设置layer.masksToBounds = true(没有效果)

提前感谢您的想法和建议.

ios uitapgesturerecognizer swift

1
推荐指数
1
解决办法
613
查看次数