上下滑動實現(xiàn)切換效果.
#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