解决pan手势和UITableView的scrollview属性上下滑动冲突

#pragma mark - ==============上拉下拉功能==============

-(void)panAction:(UIPanGestureRecognizer *)sender{

      //判断条件自定义   kDEVICEHEIGHT:   自己定义的一个高度

    if (self.tableView.frame.origin.y == kDEVICEHEIGHT- 130) {

        NSLog(@"上拉");

        //动画效果,3s内弹出tableView充满整个屏幕

        [UIView animateWithDuration:0.3 animations:^{

        

        self.alpha = 1.0;

        [self.tableView setFrame:CGRectMake(0, 0, kDEVICEWIDTH, kDEVICEHEIGHT)];

                        //self.tableView.tableHeaderView = nil;

        [self createHeaderView];

        self.tableView.tableHeaderView.alpha = 1;

        

        } completion:nil];

        

        //设置pan手势禁止,避免与tableView上下滑动的冲突

        sender.enabled = NO;

        self.tableView.scrollEnabled = YES;

    }

}

//scrollView的代理方法(tableView继承自scrollView

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

    //设置一个范围,避免tableView上拉过快直接实现下拉。

    if (scrollView.contentOffset.y <=-80) {

        //下拉手势开启   self.pan 定义的代码省略

        self.pan.enabled = YES;

        scrollView.scrollEnabled = NO;

            NSLog(@"下拉");

            [UIView animateWithDuration:0.3 animations:^{

                self.alpha = 1.0;

                [self.tableView setFrame:CGRectMake(0, kDEVICEHEIGHT - 130, kDEVICEWIDTH, kDEVICEHEIGHT)];

                self.tableView.tableHeaderView.alpha = 0;

            } completion:nil];

            NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.2 repeats:NO block:^(NSTimer * _Nonnull timer) {

                CGPoint point = CGPointMake(0, self.tableView.frame.origin.y - 180);

                self.tableView.frame.origin = point;

                self.tableView.tableHeaderView = nil;

            }];

            [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值