1

ナビゲーション バーの appdelegate ファイルに UILabel を表示しています (正確にはナビゲーション バーではありません)。完璧に見せています。しかし、それを呼び出すタッチイベントはありません。タッチはステータスバーでのみ機能します。助けてください。前もって感謝します。

これが私のコードです。

CGRect frame=[[UIApplication sharedApplication] statusBarFrame];
backgroundImageView=[[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height, 320, 44)];        
backgroundImageView.tag=50;
[backgroundImageView setTextAlignment:UITextAlignmentCenter];
[backgroundImageView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"music.png"]]];
[self.window addSubview:backgroundImageView];

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{   
    NSLog(@"in touched");
}
4

1 に答える 1

0

タイラーが彼の答えで述べているように:

UIWindow には、sendEvent と呼ばれる便利なキャッチオール メソッドがあります。これは、イベント処理パイプラインの開始近くにあるすべてのイベントを確認します。非標準の追加イベント処理を行いたい場合は、ここに配置するのが適しています。

すべてのタッチをインターセプトするには、コントローラー ビューに UIView サブクラスを使用し、hitTest:withEvent: メソッドをオーバーライドする必要があります。

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
        touchedView = [super hitTest:point withEvent:event];
        NSSet* touches = [event allTouches];
        // handle touches if you need
        return touchedView;
        }

また

2) 以下を使用できます。

UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(anyMethod)];  
[imageView addGestureRecognizer:tgr];  
[tgr release];  

Before doing this, enable user interaction of UIimageView.
于 2013-01-24T11:26:03.770 に答える