顺利隐藏导航栏

时间:2014-05-23 02:16:27

标签: ios iphone uinavigationcontroller navigation uinavigationbar

如何在调整大小视图框架(或tableView)时执行此操作? 我使用这个代码,我调整了视图,然后我向下/向上滚动 我使用代码,而不是故事板

 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
 {
if ([gestureRecognizer class] == [UIPanGestureRecognizer class])
{
    UIPanGestureRecognizer *panGestureRec = (UIPanGestureRecognizer *)gestureRecognizer;
    CGPoint distance = [panGestureRec translationInView:self.tableView];

    if (distance.y > 0 || distance.y < 0)
    {
        if (distance.y > 0) // down
        {
            //NSLog(@"user swiped down");
            [self.navigationController setNavigationBarHidden:YES animated:YES];

        } else if (distance.y < 0) //up
        {
            //NSLog(@"user swiped up");
            [self.navigationController setNavigationBarHidden:NO animated:YES];
        }

        return NO;
    } else {
        return YES;
    }
}
return YES;

}

1 个答案:

答案 0 :(得分:0)

试试这段代码。这将提供平滑的动画(使用UIView动画属性)

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
 {
if ([gestureRecognizer class] == [UIPanGestureRecognizer class])
{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2];

    UIPanGestureRecognizer *panGestureRec = (UIPanGestureRecognizer *)gestureRecognizer;
    CGPoint distance = [panGestureRec translationInView:self.tableView];

    if (distance.y > 0 || distance.y < 0)
    {
        if (distance.y > 0) // down
        {
            //NSLog(@"user swiped down");
            [self.navigationController setNavigationBarHidden:YES animated:YES];

        } else if (distance.y < 0) //up
        {
            //NSLog(@"user swiped up");
            [self.navigationController setNavigationBarHidden:NO animated:YES];
        }

        return NO;
    } else {
        return YES;
    }

   [UIView commitAnimations];
}
return YES;