• iOS Coding项目片段记录(三)


    UITableView 固定section 随着cell滚动而滚动

    实现UITableView 的下面这个方法,
    #pragma mark - Scroll
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
        CGFloat sectionHeaderHeight = 40;
           //固定section 随着cell滚动而滚动
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
            
        } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
            
        }
    
    }

    实际项目中实现:

    /frame   自定义head
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
            
            if ([self.delegate respondsToSelector:@selector(tableViewDidScroll:)]) {
                [self.delegate tableViewDidScroll:scrollView];
            }
            
        });
        
        
        if (isAnCompletion) {
            return;
        }
        [self.listTableView updateTimeLabel];
        if (lastContentOffset < scrollView.contentOffset.y) {
            //向上滚动
            //head
            //如果导航在中间
            if (self.fsofViewController.navView.frame.origin.y > 64) {
    //            self.fsofViewController.navView.hidden = YES;
                
                [UIView animateWithDuration:0.5 animations:^{
                    isAnCompletion = YES;
                    
                    self.fsofViewController.navView.alpha = 0.3;
                    self.fsofViewController.navView.alpha = -self.fsofViewController.headView.frame.origin.y/(self.fsofViewController.headView.frame.size.height-self.listuserNavbarHeight);
    //                self.fsofViewController.headView.alpha =0;
                    //导航条透明度
                    self.fsofViewController.barBgView.alpha = -self.fsofViewController.headView.frame.origin.y/(self.fsofViewController.headView.frame.size.height-self.listuserNavbarHeight);
                    
                    self.fsofViewController.headView.frame = CGRectMake(0, -self.listuserHeadHeight+self.listuserNavbarHeight, self.fsofViewController.headView.frame.size.width, self.fsofViewController.headView.frame.size.height);
                    //导航
                    self.fsofViewController.navView.frame = CGRectMake(0, self.listuserNavbarHeight, self.fsofViewController.navView.frame.size.width, self.fsofViewController.navView.frame.size.height);
                    
                    self.fsofViewController.headView.alpha =0.5;
                    //所有的list一起变
                    for (id view in self.fsofViewController.bgScrollView.subviews) {
                        if ([view isKindOfClass:[CommunityList class]]) {
                            CommunityList *cView;
                            cView = view;
                            cView.frame = CGRectMake(cView.frame.origin.x, self.listuserNavbarHeight, self.frame.size.width, [UIScreen mainScreen].bounds.size.height-self.listtabbarHeight-self.listuserNavbarHeight);
                            cView.listTableView.frame = CGRectMake(0, 0, self.frame.size.width, [UIScreen mainScreen].bounds.size.height-self.listtabbarHeight-self.listuserNavbarHeight);
                        }
                    }
                    
                } completion:^(BOOL finished) {
                    isAnCompletion = NO;
                    self.fsofViewController.headView.alpha =0;
    //                self.fsofViewController.navView.alpha = 1;
                }];
                
            }
            
        }else{
            
            if (scrollView.contentOffset.y <= -1) {
                
                //向下滚动
                [UIView animateWithDuration:0.5 animations:^{
                    isAnCompletion = YES;
                    self.fsofViewController.navView.alpha =1;
                    self.fsofViewController.headView.alpha =1;
                    self.fsofViewController.barBgView.alpha =0;
                    
                    self.fsofViewController.headView.frame = CGRectMake(0, 0, self.fsofViewController.headView.frame.size.width, self.fsofViewController.headView.frame.size.height);
                    //导航
                    self.fsofViewController.navView.frame = CGRectMake(0, self.listuserHeadHeight, self.fsofViewController.navView.frame.size.width, self.fsofViewController.navView.frame.size.height);
                    
                    
                    //所有的list一起变
                    for (id view in self.fsofViewController.bgScrollView.subviews) {
                        if ([view isKindOfClass:[CommunityList class]]) {
                            
                            CommunityList *cView;
                            cView = view;
                            
                            cView.frame = CGRectMake(cView.frame.origin.x, self.listuserHeadHeight+self.listheadHeight, self.frame.size.width, [UIScreen mainScreen].bounds.size.height-self.listuserHeadHeight-self.listheadHeight-self.listtabbarHeight);
                            
                            cView.listTableView.frame = CGRectMake(0, 0, self.frame.size.width, [UIScreen mainScreen].bounds.size.height-self.listuserHeadHeight-self.listtabbarHeight-self.listheadHeight);
                        }
                    }
                    
                    
                } completion:^(BOOL finished) {
                    isAnCompletion = NO;
                }];
            
                
                
            }
        }
        
        if(self.fsofViewController.navView.frame.origin.y == 64){
            //导航条透明度
            [UIView animateWithDuration:0.5 animations:^{
                self.fsofViewController.barBgView.alpha = 1.0;
            }];
        }else{
            
            //导航条透明度
            self.fsofViewController.barBgView.alpha = 0.0;
        }
    }
    
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
    {
        
    }
    
    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
        
        lastContentOffset = scrollView.contentOffset.y;
    }
  • 相关阅读:
    差一个引号的崩溃
    js中.toString()和String()的一丢丢区别
    PC端和手机端页面的一丢丢区别
    LINQ踩坑记录
    C# list group分组扩展,方法来源网络记录备忘
    NPOI分批读取数据
    Xamarin开发登录示例
    动态创建匿名对象利用表达式树动态构建分组条件
    安卓H5互调笔记
    WPF学习6
  • 原文地址:https://www.cnblogs.com/741162830qq/p/6030838.html
Copyright © 2020-2023  润新知