【发布时间】:2011-10-17 04:19:40
【问题描述】:
我有一个应用程序,我在图像视图中从 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”
这段代码有什么错误,所以它会显示这种类型的消息。
【问题讨论】:
-
试试这个:- [self.view sendsubviewtoback : yourscrollView]; [你的滚动视图将子视图带到前面:图像视图];可能b你的scrollView出现在你的Imageview前面所以它不会触摸......在删除scrollview后尝试tp点击一次,这样你可能会清楚它是否与ScrollView有关。
-
当你没有调用你的线程并且没有初始化自动释放池......并在你的函数完成时释放它时出现此消息..
标签: iphone xcode uiscrollview uiimageview uigesturerecognizer