标签: uitapgesturerecognizer

使用UITapGestureRecognizer

iPhone开发新手 我有一个视图,其中包含一个包含UIImageView的UIScrollView.我在图像视图上添加了一个(双)轻击手势识别器,使警报框打开.出于某种原因,我确信我只是迟钝,它开了3次.

这是我的代码:

- (void)viewDidLoad {

    scrollView.delegate = self;

    UIImage* image = imageView.image;
    imageView.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
    scrollView.contentSize = image.size;

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
    tapGesture.numberOfTapsRequired = 2;
    [imageView addGestureRecognizer:tapGesture];
    [tapGesture release];

    NSLog(@"LOADED");

    [super viewDidLoad];
}

-(IBAction) handleTapGesture:(UIGestureRecognizer *) sender {
    CGPoint tapPoint = [sender locationInView:imageView];
    int tapX = (int) tapPoint.x;
    int tapY = (int) tapPoint.y;
    NSLog(@"TAPPED X:%d Y:%d", tapX, tapY);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:nil cancelButtonTitle:@"I'm awesome." otherButtonTitles:nil];
    [alert show]; …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c gesture-recognition uitapgesturerecognizer

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

如何向UITextView添加双击手势

目前我想让UITextView有一个双击手势.似乎UITableView有自己的双击手势,当我们双击时,会选择一些文字.所以我想删除这个默认的双击手势到我自己的手势识别器.我尝试了很多方法,都失败了.似乎没有办法删除UITextView的默认识别器.我还想在这个UITextView上添加一个透明视图来做双击事件,但是这个子视图将阻止UITextView上的其他手势.是否有一些方法可以将双击手势识别器添加到UITextView?我真的希望有一个解决方案.

我仍然期待iOS5的解决方案:)

uitextview ios uitapgesturerecognizer

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

如何从另一个类调用@selector方法

是否可以从另一个类调用@selector方法?例如,我创建一个方法"bannerTapped:"并从"myViewController.m"类调用它.

myviewcontroller.m:

anotherClass *ac= [[anotherClass alloc]init];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:ac action:@selector(bannerTapped:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
cell.conversationImageView.tag = indexPath.row;
[cell.conversationImageView addGestureRecognizer:singleTap];
[cell.conversationImageView setUserInteractionEnabled:YES];
Run Code Online (Sandbox Code Playgroud)

anotherClass.m:

-(void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer {
    //do something here 
}
Run Code Online (Sandbox Code Playgroud)

更新:

viewController.m:

 #import "anotherClass.h"



 +(viewcontroller *)myMethod{
 // some code...

 anotherClass *ac= [[anotherClass alloc]init];

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:ac   action:@selector(bannerTapped:)];

}
Run Code Online (Sandbox Code Playgroud)

anotherClass.h:

-(void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer;
Run Code Online (Sandbox Code Playgroud)

anotherClass.m:

-(void)Viewdidload{
    [viewController myMethod];
     }


   -(void)bannerTapped:(UIGestureRecognizer *)gestureRecognizer {
      //do something here 
   }
Run Code Online (Sandbox Code Playgroud)

objective-c instance-methods uitapgesturerecognizer ios7

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

如何比较 iOS 上的手势类型?

我在一个视图中有两种不同类型的三种不同手势。

第一个是 a UITapGestureRecognizer,另外两个是UILongPressGestureRecognizer

长按手势识别器有不同的minimumPressDuration,一个是0.15,另一个是0.50,所以我实现了以下功能,以便识别所有手势:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer *) otherGestureRecognizer{
    return true;
}
Run Code Online (Sandbox Code Playgroud)

该功能确实允许识别所有手势,但问题是每当UILongPressGestureRecognizer识别出 a 时UITapGestureRecognizer,也识别出 a。

所以,我想知道如何比较中的gestureRecognizer的类型

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer: (UIGestureRecognizer *) otherGestureRecognizer
Run Code Online (Sandbox Code Playgroud)

或如何停止UITapGestureRecognizer的时候UILongPressGestureRecognizer检测,因为UITapGestureRecognizer每当触发UILongPressGestureRecognizer被触发。

objective-c uigesturerecognizer ios uitapgesturerecognizer ios8

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

将参数传递给使用UITapGestureRecognizer,UIImageView的和的UITableViewCell在斯威夫特一个选择

我需要确定image用户点击了一个TableCell.

如何通过TAG

class CustomCell: UITableViewCell {
@IBOutlet weak var imgPost1: UIImageView!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
    imgPost1.tag=1
    let tap = UITapGestureRecognizer(target: self, action: #selector(CustomCell.tappedMe))
    imgPost1.addGestureRecognizer(tap)
    imgPost1.userInteractionEnabled = true
}
func tappedMe(xTag:Int) {
    print(xTag)
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}
}
Run Code Online (Sandbox Code Playgroud)

uitableview uiimageview uitapgesturerecognizer swift swift2

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

UITapGestureRecognizer 和 addTarget 的区别

任何人都可以澄清这两种在点击视图时触发功能的方式之间的区别吗?

1) myView.addTarget(self, action: #selector(myFunctionToTrigger(_:)), forControlEvents: UIControlEvents.TouchUpInside)

2) let tapGesture = UITapGestureRecognizer(target: self, action: #selector(myFunctionToTrigger(_:))) myView.addGestureRecognizer(tapGesture)

ios uitapgesturerecognizer addtarget

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

UITapGestureRecognizer 阻止子视图中 UIButton 的触摸事件

我相信我在 UITapGestureRecognizer 上遇到了一个问题,用于在聊天室区域中点击时关闭键盘以防止或阻止对 previewCancelButton 的触摸。以下是我的相关代码:

基模板VC.m

- (void)addDismissKeyboardGesture {

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard:)];
    tapGesture.cancelsTouchesInView = NO;
    tapGesture.delegate = self;
    self.view.tag = 111;
    [self.view addGestureRecognizer:tapGesture];
}

- (void) dismissKeyboard:(id)sender {
    UITapGestureRecognizer *gesture = sender;
    UIView *view = gesture.view;
    NSLog(@"%ld", (long)view.tag);
    [self.view endEditing:YES];
}
Run Code Online (Sandbox Code Playgroud)

聊天室VC.m

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{

    //Disallow recognition of tap gestures in the segmented control.
    if (([touch.view isKindOfClass:[UIButton class]])) {
        NSLog(@"noooooooo");
        return NO;
    }
    return YES;
    NSLog(@"yesssssss"); 
}
Run Code Online (Sandbox Code Playgroud)

输入函数视图.m

- (void)selectedSticker:(NSString *)stickerURLString {

    /* …
Run Code Online (Sandbox Code Playgroud)

objective-c uibutton uigesturerecognizer ios uitapgesturerecognizer

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

如何调试 UIGestureRecognizers

我有不同的视图层次结构UIGestureRecognizers。有时其中一个会停止工作,我正在寻找一种有效的方法来调试它。由于UIGestureRecognizers通常的被动性质,我总是发现它们很难调试。如果一个人停止工作,我能想到的两件事就是

  • 检查视图层次结构以确保另一个视图不会阻止触摸
  • 覆盖touchesBegan:withEvent:所有相关视图以尝试追踪触摸的传递

不过,这些有时并不能解决问题,就像目前的情况一样,我UITapGestureRecognizer有时(我相信在呈现和驳回视图之后)会在应用程序运行时停止工作。

objective-c uigesturerecognizer ios uitapgesturerecognizer

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

UITapGestureRecognizer 点坐标

我正在尝试在我的应用程序中实现点击手势识别器。理想情况下,我需要点击手势返回xy坐标,因此我可以创建一个变量以使用需要xy值的参数应用于核心图像过滤器。例如,用户敲击他们的鼻子,手势识别器将坐标(一个变量,比如说,nosePosition.xnosePosition.y)传递到一个过滤器中,例如CIBumpDistorion,它需要x和 的ykCIInputCenterKey

我试过使用很多方法和移动/删除代码都无济于事。所以如果有人给我一些建议,我将不胜感激!

cgpoint ios uitapgesturerecognizer swift

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

在 UITextview 中点击单词

我添加了一个最初不可编辑的 uitextview。我添加了一个点击手势,使编辑成为真。在点击手势选择器中,我得到正在点击的单词。我尝试了很多解决方案,但没有一个作为完整的解决方案对我有用。如果不滚动 textview,则每个解决方案都有效。但是,如果我滚动 textview,则不会检索到确切的单词。这是我获取点击词的代码:

 @objc func handleTap(_ sender: UITapGestureRecognizer) {

    notesTextView.isEditable = true
    notesTextView.textColor = UIColor.white

    if let textView = sender.view as? UITextView {

        var pointOfTap = sender.location(in: textView)
        print("x:\(pointOfTap.x) , y:\(pointOfTap.y)")

        let contentOffsetY = textView.contentOffset.y
        pointOfTap.y += contentOffsetY
        print("x:\(pointOfTap.x) , y:\(pointOfTap.y)")
        word(atPosition: pointOfTap)

 }

func word(atPosition: CGPoint) -> String? {
    if let tapPosition = notesTextView.closestPosition(to: atPosition) {
        if let textRange = notesTextView.tokenizer.rangeEnclosingPosition(tapPosition , with: .word, inDirection: 1) {
            let tappedWord = notesTextView.text(in: textRange)
            print("Word: \(tappedWord)" ?? "")
            return tappedWord …
Run Code Online (Sandbox Code Playgroud)

objective-c uitextview ios uitapgesturerecognizer swift

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