iOS TabeView 頭視圖和尾視圖不滑動的實現

來源:互聯網
上載者:User

標籤:

因項目有需求不能讓section中的頭尾視圖滑動,顧根據網上的一些資料和自己整理的思路,已實現了不滑動效果,上代碼,啥都說了,搞了2個小時都是淚。。。。

1.建立一個tableview

_mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) style:UITableViewStylePlain];//帶導覽列-64_mainTableView.backgroundColor = [UIColor clearColor];_mainTableView.dataSource = self;_mainTableView.delegate  = self;_mainTableView.sectionHeaderHeight = 40;//headView高_mainTableView.sectionFooterHeight = 64;//footerView高_mainTableView.contentInset = UIEdgeInsetsMake(0, 0, -64, 0);//載入的時候需要底部視圖

2. 實現scrollView代理協議

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    CGFloat sectionHeaderHeight = 64;//設定headView和footerView的最大值    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {//headerView剛開始的滑動        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, -sectionHeaderHeight, 0);    }    else if (scrollView.contentOffset.y>=sectionHeaderHeight && scrollView.contentOffset.y + 64 < scrollView.contentSize.height - scrollView.frame.size.height) {//中間的滑動        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionHeaderHeight, 0);            }else if(scrollView.contentOffset.y + 64 >= scrollView.contentSize.height - scrollView.frame.size.height && scrollView.contentOffset.y < scrollView.contentSize.height - scrollView.frame.size.height){//footerView結束的時候的滑動        scrollView.contentInset = UIEdgeInsetsMake(0, 0,-(scrollView.contentSize.height - scrollView.frame.size.height - scrollView.contentOffset.y) , 0);    }}

 

iOS TabeView 頭視圖和尾視圖不滑動的實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.