首页 文章

双击UIview时隐藏导航栏

提问于
浏览
0

如何在双击时隐藏navigationBar并在UIView上单击显示而不使用导航控制器?还有隐藏和展示时的动画?

提前致谢 .

3 回答

  • 0
    UITapGestureRecognizer* tapGesture =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(your_selector)];
    tapGesture.numberOfTapsRequired = 2;
    [self.view addGestureRecognizer:tapGesture];
    [tapGesture release];
    

    在你的选择器中:

    -(void)your_selector{
        [UIView animateWithDuration:0.5
                     animations:^{
                         bar.frame = CGRectOffset(bar.frame, 0, bar.bounds.size.height*bar.frame.origin.y<0?-1:1);
                     }];
    }
    

    在此实现中,您只有双触事件,它会将bar的状态更改为反向 . 不幸的是,单一和双触摸手势在某一时刻并不容易实现 . 更多的人类行为,对你而言也很容易 - 只有双重触摸才能工作 .

    XCode project - example

  • 0

    你可以拥有一个没有导航控制器的 UINavigationBar

    navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 40.0f)];
    [navBar setDelegate:self];
    [mainView addSubview:navBar];
    

    UITapGestureRecognizerUIGestureRecognizer 的具体子类,用于查找单个或多个分接头:

    UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideNavBar:)];
    [doubleTap setNumberOfTapsRequired:2];
    [YOURVIEW addGestureRecognizer:doubleTap];
    
    UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showNavBar:)];
    [singleTap setNumberOfTapsRequired:1];
    [YOURVIEW addGestureRecognizer:singleTap];
    

    以下是显示或隐藏导航栏的方法:

    - (void)hideNavBar:(id)sender 
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0f]; //Animation duration in seconds
    
        navBar.alpha = 0.0f;
    
        [UIView commitAnimations];
    }
    
    - (void)showNavBar:(id)sender 
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0f]; //Animation duration in seconds
    
        navBar.alpha = 1.0f;
    
        [UIView commitAnimations];
    }
    
  • 0

    试试这个隐藏

    [UIView beginAnimations:@"Hide bar animation" context:NULL];
    
    [UIView setAnimationDuration:0.5];
    
    navigationBar.alpha = 0.0;
    
    [UIView commitAnimations];
    
    for showing
    
    [UIView beginAnimations:@"Show bar animation" context:NULL];
    
    [UIView setAnimationDuration:0.5];
    
    navigationBar.alpha = 1.0;
    
    [UIView commitAnimations];
    

    但是使用UINavigationController它太容易了......

相关问题