未检测到点击图像视图 [英] Not Detecting Tap on image view

查看:47
本文介绍了未检测到点击图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在其中我要从图像视图中的URL调用图像.图像视图被添加为滚动视图的子视图.在我的实施文件中,我使用了此代码

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():类UIView的对象0x4e412d0自动释放,没有池-只是泄漏无法访问变量"doubleTap""无法访问变量"singleTap"无法访问变量"doubleTap"无法访问变量"doubleTap"

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.

推荐答案

尝试自动释放,而不要像这样立即释放:

Try autoreleasing instead of immediately releasing like this:

//EDIT:1
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)] autorelease];
UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)] autorelease];
UITapGestureRecognizer *twoFingerTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerTap:)] autorelease];
//EDIT:2
[pool release];

然后注释掉行

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

希望这会有所帮助.

这篇关于未检测到点击图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆