首页 > 其他 > 详细

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

时间:2014-03-03 15:55:13      阅读:492      评论:0      收藏:0      [点我收藏+]

1.想实现的效果:

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

2.思路:

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

 

代码如下:

bubuko.com,布布扣
#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));
        }];
    }
    
}
bubuko.com,布布扣

 

 

ps:不要忘记设置

self.webView.scrollView.delegate = self;

demo示例:

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

ios: 仿照【ONE】应用中的阅读滑动效果,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/yoon/p/3577044.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!