未检测到图像视图上的点击
我有一个应用程序,我在图像视图中从 URL 调用图像。图像视图添加为滚动视图的子视图。在我的实现文件中,我使用了此代码
- (void)loadView {
[super loadView];
// 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];
NSURL *imgUrl=[[NSURL alloc] initWithString:@"http://www.deviantart.com/download/80153093/Sexy_Kabuto_by_dark_tarou.jpg"];
NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *img = [UIImage imageWithData:imgData];
imageView = [[UIImageView alloc] initWithImage:img];
// set the tag for the image view
[imageView setTag:ZOOM_VIEW_TAG];
[imageView addGestureRecognizer:singleTap];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:twoFingerTap];
[singleTap release];
[doubleTap release];
[twoFingerTap release];
[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];
NSLog(@"%d",imageView.tag);
}
当我在模拟器上运行时,它没有检测到点击识别器。在控制台窗口中显示此消息
2011-08-01 10:01:46.999 ImageScroll[443:1907] * __NSAutoreleaseNoPool(): UIView 类的对象 0x4e412d0 自动释放,没有池 - 只是泄漏 无法访问变量“doubleTap” ” 无法访问变量“singleTap” 无法访问变量“doubleTap” 无法访问变量“doubleTap”
这段代码中有什么错误,以至于它显示这种类型的消息。
I have an application in which i am calling image from URL in image view. Image view is add as subview of scroll view. In my implementation file i have use this code
- (void)loadView {
[super loadView];
// 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];
NSURL *imgUrl=[[NSURL alloc] initWithString:@"http://www.deviantart.com/download/80153093/Sexy_Kabuto_by_dark_tarou.jpg"];
NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *img = [UIImage imageWithData:imgData];
imageView = [[UIImageView alloc] initWithImage:img];
// set the tag for the image view
[imageView setTag:ZOOM_VIEW_TAG];
[imageView addGestureRecognizer:singleTap];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:twoFingerTap];
[singleTap release];
[doubleTap release];
[twoFingerTap release];
[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];
NSLog(@"%d",imageView.tag);
}
When i run on simulator then it did not detect tap recognizer. In console window it show this message
2011-08-01 10:01:46.999 ImageScroll[443:1907] * __NSAutoreleaseNoPool(): Object 0x4e412d0 of class UIView autoreleased with no pool in place - just leaking
Unable to access variable "doubleTap"
"
Unable to access variable "singleTap"
Unable to access variable "doubleTap"
Unable to access variable "doubleTap"
What is error in this code so that it show this type of message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您检查过“UserInteractionEnabled”吗?我相信默认情况下是“否”。 (在UIView中默认值为YES)
Have you checked "UserInteractionEnabled"? I believe it is NO by default. (In UIView the default value is YES)
尝试自动释放而不是像这样立即释放:
然后注释掉这些行
希望这会有所帮助。
Try autoreleasing instead of immediately releasing like this:
and then comment out the lines
Hope this helps.
试试这个
Try this