开发者

gesture recogniser on web view in an iphone app

开发者 https://www.devze.com 2023-04-04 15:41 出处:网络
I have created a webview to display the pdf, now using the gesture recognizer on single tap I have to call some method but single tap is not recognising

I have created a webview to display the pdf, now using the gesture recognizer on single tap I have to call some method but single tap is not recognising

I have used this code

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 450,450)];
UITapGestureRecognizer *DoubleFingerDTap = [[UITapGestureRecognizer alloc]
                                           initWithTarget:self action:@selector(screenTappedtwice:)];

DoubleFingerDTap.numberOfTapsRequired = 1;
[webView addGestureRecognizer:DoubleFingerDTap];

[DoubleFingerDTap release];

method called

- (void)screenTappedtwice:(UIGestureRecognizer *)sender {

    CGPoint tapPoint = [sender locationInView:sender.view.superview];


      [UIView beginAnimations:nil context:NULL];

    sender.view.center = tapPoint;

//Check the current state of the navigation bar...
    //BOOL navBarState = [self.navigationController isNavigationBarHidden];
//  Set the navigationBarHidden to the opposite of the current state.
//  [self.navigati开发者_Python百科onController setNavigationBarHidden:TRUE animated:YES];


    [self.navigationController setNavigationBarHidden:YES animated:YES];

    [UIView commitAnimations];


}


Have you tried setting:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;

to return YES? Also, ensure you set your tap gesture's delegate to self so that the message is properly received. I just tested this in a new project and it does work.

EDIT

Not quite sure what your animation begin & commit is for - the method setNavigationBarHidden:animated: animates itself. Additionally, the use of these animation definitions are discouraged in iOS 4 onwards - look into using block-based animations on UIView instead.

For your navigation controller, you are pretty much there - implement something like this:

- (void)screenTappedTwice:(UITapGestureRecognizer *)sender
{
    BOOL shouldHideNavBar = [self.navigationController isNavigationBarHidden] ? NO : YES;
    [self.navigationController setNavigationBarHidden:shouldHideNavBar animated:YES];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号