gpt4 book ai didi

ios - UIGesturerecognizer 不调用 shouldRecognizeSimultaneouslyWithGestureRecognizer

转载 作者:行者123 更新时间:2023-11-28 22:56:32 26 4
gpt4 key购买 nike

这是我添加手势识别器的代码

    UIImage *img = [UIImage imageWithContentsOfFile:media.thumbnailPath];
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = img;
imageView.contentMode = UIViewContentModeScaleToFill;
imageView.backgroundColor =[UIColor blackColor];

//Add tap guesture
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];

[singleTap setNumberOfTapsRequired:1];
[singleTap setDelegate:self];

[doubleTap setNumberOfTapsRequired:2];
[doubleTap setDelegate:self];

[singleTap requireGestureRecognizerToFail:doubleTap];

[imageView addGestureRecognizer:singleTap];
[imageView addGestureRecognizer:doubleTap];
[singleTap release];
[doubleTap release];

我已经实现了

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
NSLog(@"Gesturing");
return YES;
}

但是在处理单击手势时不会调用委托(delegate)方法,但它适用于双击手势

最佳答案

查看 Simultaneous gesture recognizers in Iphone SDK

For most cases you don't need to:

setup a delegate
permit simultaneous gesture recognition (unless you want simultaneous swipes; not likely)

设置手势识别器

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] 
initWithTarget:self
action:@selector(handleSingleTapOnMainImageView:)];

[imageView addGestureRecognizer:singleTap];
[singleTap release];

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleDoubleTapOnMainImageView:)];
[doubleTap setNumberOfTapsRequired:2];
[singleTap requireGestureRecognizerToFail:doubleTap];
[imageView addGestureRecognizer:doubleTap];
[doubleTap release];

方法实现

-(void)handleSingleTapOnMainImageView:(UIGestureRecognizer*)gestureView
{
NSLog(@"handleSingleTapOnMainImageView");
}

-(void)handleDoubleTapOnMainImageView:(UIGestureRecognizer*)gestureView
{
NSLog(@"handleDoubleTapOnMainImageView");
}

关于ios - UIGesturerecognizer 不调用 shouldRecognizeSimultaneouslyWithGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10687399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com