gpt4 book ai didi

iphone - UITap手势识别器

转载 作者:行者123 更新时间:2023-12-03 18:27:48 26 4
gpt4 key购买 nike

我查看了 Apple 的 ScrollView 套件示例代码。当我在代码中使用它时,当我没有进行任何更改时它不起作用。我只是想知道如何无法双击来撤消 ScrollView 内部的缩放?我似乎无法弄清楚。我从 URL 插入图像,同时在示例代码中将图像拖动到界面生成器中。我也尝试使用相同的代码,但识别图像上的点击不起作用。为什么会发生我无法得到它?我还在下面展示了我的代码:

- (void)loadView {
[super loadView];

// set the tag for the image view
[imageView setTag:ZOOM_VIEW_TAG];

// add gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
UITapGestureRecognizer *twoFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)];

[doubleTap setNumberOfTapsRequired:2];
[twoFingerTap setNumberOfTouchesRequired:2];

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

[singleTap release];
[doubleTap release];
[twoFingerTap release];

NSURL *imgUrl=[[NSURL alloc] initWithString:@"http://www.iso.org/iso/alan_bryden_larger.jpg"];
NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *img = [UIImage imageWithData:imgData];
imageView = [[UIImageView alloc] initWithImage:img];

[self.imageScrollView addSubview:imageView];
[imgUrl release];

// calculate minimum scale to perfectly fit image width, and begin at that scale
float minimumScale = [imageScrollView frame].size.width / [imageView frame].size.width;
[imageScrollView setMinimumZoomScale:minimumScale];
[imageScrollView setZoomScale:minimumScale];}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [imageScrollView viewWithTag:ZOOM_VIEW_TAG];}


- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
[scrollView setZoomScale:scale+0.01 animated:NO];
[scrollView setZoomScale:scale animated:NO];}

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
// double tap zooms in
float newScale = [imageScrollView zoomScale] * ZOOM_STEP;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[imageScrollView zoomToRect:zoomRect animated:YES];}

- (void)handleTwoFingerTap:(UIGestureRecognizer *)gestureRecognizer {
// two-finger tap zooms out
float newScale = [imageScrollView zoomScale] / ZOOM_STEP;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
[imageScrollView zoomToRect:zoomRect animated:YES];}

最佳答案

除非您设置了 userInteractionEnabled = YES,否则您的 UIImageView 不会将触摸传递给 UIGestureRecognizer

关于iphone - UITap手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6844365/

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