上下滑动实现切换效果.

上下滑动实现切换效果.

#import "ViewController1.h"

@interface ViewController1 ()@property (nonatomic , strong) UITableView * topTableView;

@property (nonatomic , strong) UITableView * bottomTableView;

@property (nonatomic, strong) UIView * topTableFootView;

@property (nonatomic , strong) UIView * bottomTableFootView;

@end

@implementation ViewController1

- (void)viewDidLoad

{

self.automaticallyAdjustsScrollViewInsets = NO;

_topTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain];

[self.view addSubview:_topTableView];

_topTableView.delegate = self;

_topTableView.dataSource = self;

//    [_topTableView addSubview:self.topTableFootView];

//    _topTableView.tableHeaderView = self.topTableFootView;

_topTableView.bounces = YES;

//    _topTableView.tableFooterView = self.topTableFootView;

_topTableView.backgroundColor = [UIColor redColor];

[_topTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"tab1"];

_topTableView.contentInset = UIEdgeInsetsMake(-50, 0, 50, 0);

[_topTableView addSubview:self.topTableFootView];

_bottomTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height+64, self.view.frame.size.width, self.view.frame.size.height-64) style:UITableViewStylePlain];

[self.view addSubview:_bottomTableView];

_bottomTableView.delegate = self;

_bottomTableView.dataSource = self;

_bottomTableView.backgroundColor = [UIColor greenColor];

[_bottomTableView addSubview:self.bottomTableFootView];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

if (scrollView == self.topTableView) {

if (self.topTableView.contentOffset.y > 50) {

[UIView animateWithDuration:0.5 animations:^{

self.topTableView.frame = CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height-64);

self.bottomTableView.frame = CGRectMake(0,64, self.view.frame.size.width, self.view.frame.size.height-64);

} completion:^(BOOL finished) {

}];

}

}

if (scrollView == self.bottomTableView) {

if (self.bottomTableView.contentOffset.y < -50) {

[UIView animateWithDuration:0.5 animations:^{

self.topTableView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64);

self.bottomTableView.frame = CGRectMake(0, self.view.frame.size.height+64, self.view.frame.size.width, self.view.frame.size.height-64);

} completion:^(BOOL finished) {

}];

}

}

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return 0;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"tab1" forIndexPath:indexPath];

return cell;

}

- (UIView *)topTableFootView

{

if (!_topTableFootView) {

_topTableFootView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-64-30, self.view.frame.size.width, 30)];

_topTableFootView.backgroundColor = [UIColor yellowColor];

}

return _topTableFootView;

}

- (UIView *)bottomTableFootView

{

if(!_bottomTableFootView)

{

_bottomTableFootView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];

_bottomTableFootView.backgroundColor = [UIColor blueColor];

}

return _bottomTableFootView;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    十年一品温如言1008阅读 1,705评论 0 3
  • 1、设置UILabel行间距 NSMutableAttributedString* attrString = [[...
    FF_911阅读 1,405评论 0 3
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,452评论 9 5
  • 仪山禅师有一位个性谦和恭顺、努力勤劳的弟子,平时侍奉禅师的生活起居。 有一晚,仪山禅师要洗脚,他提桶热水,放...
    母亲河畔那棵小草阅读 378评论 0 0
  • たくさんの神社が存在する京都には、初詣の為に毎年数多くの方が集います。数が多すぎて、初詣にはどこが良いのか悩んでし...
    丸丸子说阅读 465评论 0 1