gpt4 book ai didi

ios - 如何识别iOS中的单个单击和双击 View ?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:48 25 4
gpt4 key购买 nike

在我的应用程序中,想要识别单击和双击 View 。我的实际问题是双击 View 时也发生了单击。单击即可完美运行..所以如何识别单个单击和双击 View ?

我的代码是:

- (void)viewDidLoad
{
[super viewDidLoad];
[self fullscreenGallery];
[self video_image_Gallery];
}
-(void)video_image_Gallery
{
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.delegate = self;
[image_scroll addGestureRecognizer:doubleTap];
}
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer
{
[self performSelector:@selector(fullscreenGallery) withObject:nil afterDelay:3];
UIScrollView * imageScroll = (UIScrollView *)gestureRecognizer.view;
self.header_view.hidden=NO;
float newScale = [imageScroll zoomScale] + ZOOM_STEP;
if (newScale > imageScroll.maximumZoomScale)
{
newScale = imageScroll.minimumZoomScale;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[imageScroll zoomToRect:zoomRect animated:YES];
}
else
{
self.header_view.hidden=YES;
newScale = imageScroll.maximumZoomScale;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[imageScroll zoomToRect:zoomRect animated:YES];
}
}

最佳答案

在您的应用程序中使用以下代码

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:    self action:@selector(handleSingleTap)];
singleTap.numberOfTapsRequired = 1;
singleTap.delaysTouchesEnded = YES;

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action:@selector(handleDoubleTap)];
doubleTap.numberOfTapsRequired = 2;


[singleTap requireGestureRecognizerToFail:doubleTap];

[self.view addGestureRecognizer:singleTap];
[self.view addGestureRecognizer:doubleTap];


-(void)handleSingleTap
{
NSLog(@"The single tap happened");
}

-(void)handleDoubleTap
{
NSLog(@"The double tap happened");
}

上面的代码完美地工作。我尝试了上面的编码。它单独工作。检查它。

关于ios - 如何识别iOS中的单个单击和双击 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32456079/

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