zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    apache开源项目 -- Wicket
    读书笔记--《机器人时代》
    apache开源项目--dbutils
    apache开源项目--mina
    apache开源项目--OpenMeetings
    apache开源项目--lume
    apache开源项目--Sirona
    shared_ptr的简单实现
    高并发网络编程之epoll详解
    最长公共子序列|最长公共子串|最长重复子串|最长不重复子串|最长回文子串|最长递增子序列|最大子数组和
  • 原文地址:https://www.cnblogs.com/yoon/p/3577044.html
Copyright © 2011-2022 走看看