美文网首页iOS进阶
iOS动效——滚动隐藏工具条和导航栏(所谓沉浸式阅读?)

iOS动效——滚动隐藏工具条和导航栏(所谓沉浸式阅读?)

作者: 邓龙 | 来源:发表于2016-04-25 16:04 被阅读1019次

    1.效果图

    工具条滚动隐藏与出现.gif

    2.关键代码

    #pragma mark - 关键代码:动画设置
    - (void)setIsExpand:(BOOL)isExpand{
        [UIView animateWithDuration:0.25 delay:0.0 usingSpringWithDamping:0.4 initialSpringVelocity:10.0 options:UIViewAnimationOptionTransitionCurlUp animations:^{
            self.bottomCon.constant = isExpand?44.0f:0.0f;
            [self.view layoutIfNeeded];
        } completion:^(BOOL finished) {
            _isExpand = isExpand;
        }];
        [self.navigationController setNavigationBarHidden:!isExpand animated:YES];
        
    #pragma clang diagnostic push
    #pragma clang diagnostic ignored"-Wdeprecated-declarations"
        [[UIApplication sharedApplication] setStatusBarHidden:!isExpand withAnimation:NO];
    #pragma clang diagnostic pop
    }
    
    
    #pragma mark - 关键代码:滚动方向判断
    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
        self.lastContentOffset = scrollView.contentOffset.y;
    }
    
    - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
        if (self.lastContentOffset < scrollView.contentOffset.y) {
            NSLog(@"向上滚动");
            if (self.isExpand) {
                self.isExpand = NO;
            }
        }else{
            NSLog(@"向下滚动");
            if (!self.isExpand) {
                self.isExpand = YES;
            }
        }
    }
    

    3.实例地址

    https://github.com/jiben071/DLAutolayoutAnimationTest

    相关文章

      网友评论

        本文标题:iOS动效——滚动隐藏工具条和导航栏(所谓沉浸式阅读?)

        本文链接:https://www.haomeiwen.com/subject/syqqrttx.html