UITableview 相关

侧滑自定义按钮

UITableView的侧滑删除增加多个按钮 - 简书

获取点击位置

 CGRect cellFrame = cell.frame;
        CGFloat tableViewOffsetY = _tableView.contentOffset.y;
        CGRect frame = CGRectMake(0 , cellFrame.origin.y - tableViewOffsetY , cellFrame.size.width , cellFrame.size.height);

获取点击按钮坐标

UITableViewCell*cell=(UITableViewCell*)btn.superview.superview;

NSIndexPath *indexPath = [_tjTabView indexPathForCell:cell];

CGRect rectInTableView = [_tjTabView rectForRowAtIndexPath:indexPath];

CGRect rect = [_tjTabView convertRect:rectInTableView toView:[_tjTabView superview]];

reloaddata偏移问题

 self.tableView.estimatedRowHeight = 0;
 self.tableView.estimatedSectionHeaderHeight = 0;
 self.tableView.estimatedSectionFooterHeight = 0;

禁止侧滑

首先写这个方法

-(void)popGestureChange:(UIViewController *)vc enable:(BOOL)enable{

    if ([vc.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        //遍历所有的手势

        for (UIGestureRecognizer *popGesture in vc.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {

            popGesture.enabled = enable;

        }

    }

}

然后在viewDidAppear这个方法里面调用

- (void)viewDidAppear:(BOOL)animated{

    [superviewDidAppear:animated];

    [self popGestureChange:self enable:NO];

}



 

1.长按拖拽排序
- (void)longPressRecognizer:(UILongPressGestureRecognizer *)longPress{
    //获取长按的点及cell
    CGPoint location = [longPress locationInView:self.myTableView];
    NSIndexPath *indexPath = [self.myTableView indexPathForRowAtPoint:location];
    UIGestureRecognizerState state = longPress.state;
    
    static UIView *snapView = nil;
    static NSIndexPath *sourceIndex = nil;
    switch (state) {
        case UIGestureRecognizerStateBegan:{
            if (indexPath) {
                sourceIndex = indexPath;
                UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:indexPath];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                snapView = [self customViewWithTargetView:cell];
                
                __block CGPoint center = cell.center;
                snapView.center = center;
                snapView.alpha = 0.0;
                [self.myTableView addSubview:snapView];
                
                [UIView animateWithDuration:0.1 animations:^{
                    center.y = location.y;
                    snapView.center = center;
                    snapView.transform = CGAffineTransformMakeScale(1.05, 1.05);
                    snapView.alpha = 0.5;
                    
                    cell.alpha = 0.0;
                }];
            }
        }
            break;
            
        case UIGestureRecognizerStateChanged:{
            CGPoint center = snapView.center;
            center.y = location.y;
            snapView.center = center;
            
            UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:sourceIndex];
            cell.alpha = 0.0;
            
            if (indexPath && ![indexPath isEqual:sourceIndex]) {
                
                [self.dataArrayM exchangeObjectAtIndex:indexPath.row withObjectAtIndex:sourceIndex.row];
                
                [self.myTableView moveRowAtIndexPath:sourceIndex toIndexPath:indexPath];
                
                sourceIndex = indexPath;
            }
            
        }
            break;
            
        default:{
            UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:sourceIndex];
            [UIView animateWithDuration:0.25 animations:^{
                snapView.center = cell.center;
                snapView.transform = CGAffineTransformIdentity;
                snapView.alpha = 0.0;
                
                cell.alpha = 1.0;
            } completion:^(BOOL finished) {
                [snapView removeFromSuperview];
                snapView = nil;
            }];
            sourceIndex = nil;
        }
            break;
    }
}
- (void)dragButtonClick:(UIButton *)button{
    //添加长按手势
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressRecognizer:)];
    self.longPress = longPress;
    longPress.minimumPressDuration = 0.0;
    [button addGestureRecognizer:longPress];
}
//截取选中cell
- (UIView *)customViewWithTargetView:(UIView *)target{
    UIGraphicsBeginImageContextWithOptions(target.bounds.size, NO, 0);
    [target.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    UIView *snapshot = [[UIImageView alloc] initWithImage:image];
    snapshot.layer.masksToBounds = NO;
    snapshot.layer.cornerRadius = 0.0;
    snapshot.layer.shadowOffset = CGSizeMake(-5.0, 0.0);
    snapshot.layer.shadowRadius = 5.0;
    snapshot.layer.shadowOpacity = 0.4;
    
    return snapshot;
}

2.滚动到指定位置

[_chatTabview reloadData];
    [_chatTabview layoutIfNeeded];

    if (_chatArr.count>0) {
        NSIndexPath* indexPath = [NSIndexPath indexPathForRow:_chatArr.count-1 inSection:0];
        [_chatTabview scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }

NSIndexPath * row = [NSIndexPath indexPathForRow:3 inSection:1];
[_circleTabView scrollToRowAtIndexPath:row atScrollPosition:UITableViewScrollPositionTop animated:YES];

3.隐藏滚动条

TabView.showsVerticalScrollIndicator = NO;

.将UITableView的高度减去底部TabBar的高度

UITableView *_tableView = [[UITableView alloc]

initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-self.tabBarController.tabBar.frame.size.height)

style:UITableViewStyleGrouped];

2.改变UITableView的滑动视图范围

_tableView.contentInset = UIEdgeInsetsMake(0, 0, self.tabBarController.tabBar.frame.size.height, 0);

4.禁止滑动

tableView.scrollEnabled = NO;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值