如何实现Google+公共个人资料页面,如导航标题动画

时间:2014-07-05 21:05:00

标签: ios uinavigationbar google-plus

enter image description here enter image description here

我有一个场景,我想要谷歌+个人资料页面,如标题动画,其中没有导航栏,但当我们向上和向下滚动导航和状态栏时,动画显示。任何人都可以帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

容易腻:

float lastOffset;

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{        

    float offset = scrollView.contentOffset.y;


    if ( offset > lastOffset ) {

       [self hideNavigationBar];
    } else  {

        [self showNavigationBar];
    }
}
- (void)hideNavigationBar
{



    CALayer *layer = self.viewParent.navigationController.navigationBar.layer;


    CGPoint navBarDefaultPosition = CGPointMake((int)self.view.frame.size.width/2.0f,42);


    if (layer.position.x == navBarDefaultPosition.x &&
        layer.position.y == navBarDefaultPosition.y && self.data.count > 0) {
        [UIView animateWithDuration:0.25 animations:^{
            layer.position = CGPointMake(layer.position.x,
                                         -self.navigationController.navigationBar.frame.
                                         size.height);

        }];
    }  
}

-(void)showNavigationBar
{

    CALayer *layer = self.viewParent.navigationController.navigationBar.layer;

    CGPoint navBarDefaultPosition = CGPointMake((int)self.view.frame.size.width/2.0f,42);

    if ( layer.position.y != navBarDefaultPosition.x ) { 

        [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
            layer.position = CGPointMake(self.view.frame.size.width/2,42);



        } completion:^(BOOL finished) {

        }];
    }
}