IOS-DEMO2 SliderToDeleteDemo

描述:项目中android用到的滑动删除。网上没找到类似就自己做了一个。

效果图:



思路:
     思路1.每个cell里面加一个scrollView 这个可能消耗太大没尝试。
     思路2.给cell中添加pan手势

完成中遇到的问题与长进:
     1.复习了block与table那套轻量级的绑定 但是发现具体问题出现时需要修改的还是不少。  
     2.可以通过设置gesture的delegate可以控制什么时候捕获手势。如ex1


ex1:
- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{

   
    if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
        CGPoint velocityPoint = [gestureRecognizer velocityInView:self];
        if (fabsf(velocityPoint.x) > 100.0) {
            return YES;
        }else
            return NO;
    }else
        return NO;
   
}


//
//  PLLSilderToDelete.m
//  SliderToDeleteDemo
//
//  Created by liu poolo on 14-7-29.
//  Copyright (c) 2014年 liu poolo. All rights reserved.
//

#import "PLLSilderToDelete.h"

@implementation PLLSilderToDelete(cell_sliderDeleSetValuePro)
- (void)configureForPLSetValueProtocol:(id<PLLSliderDeleteSetValuePro>) p{

    self.hideLabel.text=[p backgroundStr];
    self.topLabel.text=[p topLabelStr];
    self.cellView.backgroundColor=[p color];

}

@end
@interface PLLSilderToDelete(){
    CGPoint defalutCenter;
}

@end

@implementation PLLSilderToDelete

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [[NSBundle mainBundle]loadNibNamed:@"sliderDemo" owner:self options:nil];
        [self.contentView addSubview:self.cellView];
        UIPanGestureRecognizer* pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
        pan.delegate=self;
        [self.topContentView addGestureRecognizer:pan];
    }
    return self;
}

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{
   
    if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
        CGPoint velocityPoint = [gestureRecognizer velocityInView:self];
        if (fabsf(velocityPoint.x) > 100.0) {
            return YES;
        }else
            return NO;
    }else
        return NO;
   
}

-(void)handlePan:(UIPanGestureRecognizer*)gesture{
    NSLog(@"%@",    self.hideLabel);
    if(gesture.state==UIGestureRecognizerStateBegan){
        NSLog(@"begin");
        defalutCenter=self.topContentView.center;
    }else if(gesture.state==UIGestureRecognizerStateChanged){

        CGPoint translation=[gesture translationInView:gesture.view.superview];
        if(translation.x<0){
            self.topContentView.center=CGPointMake(defalutCenter.x+translation.x, defalutCenter.y);
            float alpha=1.0-(translation.x/self.cellView.frame.size.width);
            self.topContentView.alpha=alpha;
        }

    }else if(gesture.state==UIGestureRecognizerStateEnded){
        CGPoint translation=[gesture translationInView:gesture.view.superview];
        if (translation.x<-50) {
            [UIView animateWithDuration:0.3 animations:^{
                self.topContentView.frame=CGRectMake(-self.topContentView.frame.size.width, self.topContentView.frame.origin.y,self.topContentView.frame.size.width, self.topContentView.frame.size.height);
            } completion:^(BOOL finished) {
                [self.delegate silderDoWithIndex:self.contentView.tag];
                self.topContentView.frame=CGRectMake(0, self.topContentView.frame.origin.y,self.topContentView.frame.size.width, self.topContentView.frame.size.height);
                self.topContentView.alpha=1.0f;
            }];
        }else if(gesture.state==UIGestureRecognizerStateEnded){
            [UIView animateWithDuration:0.3 animations:^{
                self.topContentView.frame=CGRectMake(0, self.topContentView.frame.origin.y,self.topContentView.frame.size.width, self.topContentView.frame.size.height);
                self.topContentView.alpha=1.0f;
            } completion:nil];
        }
    }
}


- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明 YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明YOLO高分设计资源源码,详情请查看资源内容中使用说明

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值