• ios: 仿照【ONE】应用中的阅读滑动效果


    1.想实现的效果:

    浏览文章的时候,当向下滑动时候,navigationBar 和 toolbar 隐藏 , 当到结尾时候再向上滑动,navigationBar 和 toolbar 重新显示出来。

    2.思路:

    首先,这里用来显示文章的是webview ,我们都知道webview中包含scrollview,这样就好办了,我们利用scrollview来实现即可。

    代码如下:

    #pragma mark - UIScrollViewDelegate
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        int currentPostion = scrollView.contentOffset.y;
        if (currentPostion - lastPostion > kSlide && currentPostion > 0) {
            lastPostion = currentPostion;
            
            //重设frame
            [UIView animateWithDuration:kAnimationTime animations:^{
                CGRect rc = self.navigationController.navigationBar.frame;
                self.navigationController.navigationBar.frame = CGRectMake(0, -CGRectGetHeight(rc), CGRectGetWidth(rc), CGRectGetHeight(rc));
                
                rc= self.toolbar.frame;
                self.toolbar.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, CGRectGetWidth(rc), CGRectGetHeight(rc));
            
                self.webView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
            }];
        }
        else if (lastPostion - currentPostion > kSlide && (currentPostion  <= scrollView.contentSize.height-scrollView.bounds.size.height-kSlide))
        {
            lastPostion = currentPostion;
    
                    //重设frame
            [UIView animateWithDuration:kAnimationTime animations:^{
                CGRect rc = self.navigationController.navigationBar.frame;
                self.navigationController.navigationBar.frame = CGRectMake(0, 0, CGRectGetWidth(rc), CGRectGetHeight(rc));
                
                rc= self.toolbar.frame;
                self.toolbar.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - CGRectGetHeight(rc), CGRectGetWidth(rc), CGRectGetHeight(rc));
                
                self.webView.frame = CGRectMake(0, CGRectGetHeight(self.navigationController.navigationBar.frame), [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - CGRectGetHeight(self.navigationController.navigationBar.frame) - CGRectGetHeight(rc));
            }];
        }
        
    }

    ps:不要忘记设置

    self.webView.scrollView.delegate = self;

    demo示例:

    http://pan.baidu.com/s/1gd7khyF

  • 相关阅读:
    深度学习时代的图模型,清华发文综述图网络
    深入解析CNN pooling 池化层原理及其作用
    如何理解线性回归中的“回归”,回归到哪里?
    线性回归中“回归”的含义
    深度学习基础——Epoch、Iteration、Batchsize
    手动清空微信PC客户端数据
    Mini-batch 和batch的区别
    Python中绘制场景热力图
    HSV颜色识别-HSV基本颜色分量范围
    Android拨打接听电话自动免提
  • 原文地址:https://www.cnblogs.com/yoon/p/3577044.html
Copyright © 2020-2023  润新知