1

iOS アプリでは、いくつかのコンテンツを表示し、この UIWebView を閉じるために使用する UIWebView があり、次のメカニズムを使用します。

UIWebView の上に DoubleTapView (UIView のサブクラス) を配置します。

この DoubleTapView は、ダブルタップ イベントをキャッチし、適切なコードを実行して自身と UIWebView を閉じます。この時点までは正常に動作します。

ここに問題があります: UIWebView が関心のあるすべてのイベント (コンテンツのスクロール、リンクのタップなど) は通過しません。それらは DoubleTapView によってブロックされます。どうすればこれを解決できますか?

実際、今説明した内容では、DoubleTapView の代わりに UIView を使用することもできました。しかし、私は UIView を DoubleTapView でサブクラス化するつもりでした。- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; または - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event; 私の問題を解決するために、私は何か間違ったことをしているに違いありません.

パーツをまとめるために書いたコードを次に示します。

    webView=[[UIWebView alloc] initWithFrame:varFrame];
    webView.delegate=self;
    quitGesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(quitWeb:)];
    quitGesture.numberOfTapsRequired=2;
    varFrame.origin=CGPointZero;
    quitSensor=[[DoubleTapView alloc] initWithFrame:varFrame];
    quitSensor.userInteractionEnabled=YES;
    [quitSensor addGestureRecognizer:quitGesture];
    [webView addSubview:quitSensor];

DoubleTapView のメソッドを実装するときに試したのは次のとおりです。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [[self superview] touchesBegan:touches withEvent:event];
}

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    [[self superview] motionBegan:motion withEvent:event];
}
4

0 に答える 0