1

我成功地在我的 UIWebView 上实现了 UIGestureRecognizer,如下所示:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self 
                                                                          action:@selector(handleTap)];
    tap.numberOfTapsRequired = 1;

    [myUniqueWebView addGestureRecognizer:tap];

以下代码有一些错误,但逻辑是这样的:我想点击一个视图来隐藏 NavBar,如果它已经隐藏了,我想使用相同的逻辑来显示它。它不起作用:

-(void) handleTap {
    NSInteger didHideNavBar;
    didHideNavBar = 0;
    if ((didHideNavBar = 0)) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        didHideNavBar = 1;
        NSLog(@"tap1");
    } 
    if ((didHideNavBar = 1)) {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        NSLog(@"tap2");
    }
}

Xcode 向我显示“tap2”消息,但没有任何反应。

4

4 回答 4

1

您应该在方法didHideNavBar外部声明并在 first 的末尾添加,如下所示:handleTapreturn;if

NSInteger didHideNavBar = 0;
-(void) handleTap {
    if ((didHideNavBar = 0)) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        didHideNavBar = 1;
        NSLog(@"tap1");
        return;
    } 
    if ((didHideNavBar = 1)) {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        didHideNavBar = 0;
        NSLog(@"tap2");
    }
}
于 2012-06-12T12:24:59.237 回答
0

看你的代码。您将 didHideNavBar 变量设置为 0,如果条件设置为 1,您的导航栏将隐藏然后显示。你将无法看到这个肌动蛋白,因为它会在很短的时间内完成。

于 2012-06-12T12:25:36.727 回答
0

嗨,请保持didHideNavBar静态,因为每当调用 handleTap方法时,它都会将零值赋给didHideNavBar.

所以做这个改变

static NSInteger didHideNavBar = 0;
于 2012-06-12T12:40:56.367 回答
0
-(void) handleTap {

    BOOL isHidden = (parentViewController.navigationController.navigationBar.alpha == 0);
    self.navigationController.navigationBar.alpha = (isHidden) ? 1 : 0;
}
于 2012-06-12T13:07:43.863 回答