0

私は画像ビューで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); 
} 

私はシミュレータ上で実行すると、タップ認識機能を検出しませんでした。ちょうど漏洩 - 場所でないプールに自動解放クラスのUIViewのオブジェクト0x4e412d0:01:46.999 ImageScroll [443:1907] * __NSAutoreleaseNoPool()コンソールウィンドウにこのメッセージ

2011-08-01 10を示し それ表示されるように、このコードではエラーは何ですか」 変数にアクセスすることができません 『singleTap』を 変数にアクセスすることができません 『ダブルタップ』を 変数にアクセスすることができません 『ダブルタップ』を

変数「ダブルタップ」 にアクセスすることができません。このタイプのメッセージ。

+0

をお試しください: - [self.viewのsendsubviewtoback:yourscrollView]; [yourscrollview bringubviewtofront:imageview]; bあなたのscrollViewはyourImageviewの前に来るので、触れてはいけません.... scrollviewを削除した後にtp tapを一度試してみてください。そうすれば、ScrollViewに関連する問題であるかどうかわかります。 –

+0

このメッセージは、スレッドを呼び出さずにautoreleasepoolを初期化していないときに表示され、ur機能が完了したら解放します。 – AJPatel

答えて

0

はすぐにこのように解放するのではなく、自動解放してください(UIViewのではデフォルト値はYESです):

//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]; 

をコメントアウトこの情報がお役に立てば幸いです。

+0

それは働いていません。このメッセージを表示する2011-08-01 10:01:46.999 ImageScroll [443:1907] * __NSAutoreleaseNoPool():UIViewクラスのオブジェクト0x4e412d0がプールなしでオートリースされました - ちょうどリークしました – ram

+0

それをチェックしてください。私は自分の答えを編集しました。 '// EDIT:1'と' // EDIT:2'の下にある行を確認してください –

+0

私はコンソールにmsgを表示しませんでしたが、実行しません。このビューをアップロードすると、実行せずにプログラムを終了します。 – ram

3

「UserInteractionEnabled」にチェックを入れましたか?私はそれがデフォルトではNOだと信じています。

+0

これを有効にしていますが、まだこの問題が発生します。 – ram

0

これを試してみてください。この

[self.view addGestureRecognizer:singleTap]; 
    [self.view addGestureRecognizer:doubleTap]; 
    [self.view addGestureRecognizer:twoFingerTap]; 
関連する問題