Gesture recognition with UIWebView

前端 未结 6 1389
孤街浪徒
孤街浪徒 2021-02-04 10:58

I have set up some gesture recognition in an app that I\'m building. One of the gestures is a single finger single tap, which hides the toolbar at the top of the screen. Works g

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-04 11:53

    OK, so one "hack-ish" workaround is to make the view controller which houses the UIWebView a delegate of the gesture recognizer that you instantiate(UIGestureRecognizerDelegate) I am usually not a fan of solutions like this one, but...

    Assign the gesture recognizer to the view that wraps you web view, and set it's delegate to self.

    then in the delegate method gestureRecognizer:shouldRecieveTouch method, set the state to indicate the there was a tap event,

    Return NO from the delegate method so the event propagates down the responder chain to the UIWebView.

    -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    
        _userTapped = YES;
        [self performSelectorOnMainThread:@selector(hideMenuIfNotLink) afterDelay:??.?];
    //??.?? amount of time to lapse to see if shouldStartLoadWithRequest gets called.
       return NO;
    
    }
    
    -(void)hideMenuIfNotLink{
        if(_userTapped)
             //hideMenu
    }
    

    Now, in your UIWebViewDelegate shouldStartLoadWithRequest (which gets called when a user has in fact clicked a link)

    if(_userTapped){
        _userTapped = NO;
         //possibly code to reshow or verify keep showing menu
    }
    

提交回复
热议问题