美文网首页
上下滑动实现切换效果.

上下滑动实现切换效果.

作者: IceWall_Rin | 来源:发表于2016-06-15 17:21 被阅读186次

    上下滑动实现切换效果.

    #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

    相关文章

      网友评论

          本文标题:上下滑动实现切换效果.

          本文链接:https://www.haomeiwen.com/subject/ovfudttx.html