GithubHelp home page GithubHelp logo

ysldraggablecardcontainer's Introduction

YSLDraggableCardContainer

Demo

Dragging Animation

Dome Dome

Undo Animation

Dome

Requirement

not support landscape

iOS 7.0 or later

Install

Manually

Copy YSLDraggableCardContainer directory to your project.

CocoaPods

not support

Usage

#import "YSLDraggableCardContainer.h"

#define RGB(r, g, b)	 [UIColor colorWithRed: (r) / 255.0 green: (g) / 255.0 blue: (b) / 255.0 alpha : 1]

@interface ViewController () <YSLDraggableCardContainerDelegate, YSLDraggableCardContainerDataSource>

@property (nonatomic, strong) YSLDraggableCardContainer *container;
@property (nonatomic, strong) NSMutableArray *datas;

@end

@implementation ViewController

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    _container = [[YSLDraggableCardContainer alloc]init];
    _container.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    _container.backgroundColor = [UIColor clearColor];
    _container.dataSource = self;
    _container.delegate = self;
    _container.canDraggableDirection = YSLDraggableDirectionLeft | YSLDraggableDirectionRight;
    [self.view addSubview:_container];
    
    _datas = [NSMutableArray array];
    for (int i = 0; i < 7; i++) {
        NSDictionary *dict = @{@"image" : [NSString stringWithFormat:@"photo_sample_0%d",i + 1],
                               @"name" : @"YSLDraggableCardContainer Demo"};
        [_datas addObject:dict];
    }

    [_container reloadCardContainer];
}

#pragma mark -- YSLDraggableCardContainer DataSource
- (UIView *)cardContainerViewNextViewWithIndex:(NSInteger)index
{
    NSDictionary *dict = _datas[index];
    CardView *view = [[CardView alloc]initWithFrame:CGRectMake(10, 64, self.view.frame.size.width - 20, self.view.frame.size.width - 20)];
    view.backgroundColor = [UIColor whiteColor];
    view.imageView.image = [UIImage imageNamed:dict[@"image"]];
    view.label.text = [NSString stringWithFormat:@"%@  %ld",dict[@"name"],(long)index];
    return view;
}

- (NSInteger)cardContainerViewNumberOfViewInIndex:(NSInteger)index
{
    return _datas.count;
}

#pragma mark -- YSLDraggableCardContainer Delegate
- (void)cardContainerView:(YSLDraggableCardContainer *)cardContainerView didEndDraggingAtIndex:(NSInteger)index draggableView:(UIView *)draggableView draggableDirection:(YSLDraggableDirection)draggableDirection
{
    if (draggableDirection == YSLDraggableDirectionLeft) {
        [cardContainerView movePositionWithDirection:draggableDirection
                                         isAutomatic:NO];
    }
    
    if (draggableDirection == YSLDraggableDirectionRight) {
        [cardContainerView movePositionWithDirection:draggableDirection
                                         isAutomatic:NO];
    }
}

- (void)cardContainderView:(YSLDraggableCardContainer *)cardContainderView updatePositionWithDraggableView:(UIView *)draggableView draggableDirection:(YSLDraggableDirection)draggableDirection widthRatio:(CGFloat)widthRatio heightRatio:(CGFloat)heightRatio
{
    CardView *view = (CardView *)draggableView;
    
    if (draggableDirection == YSLDraggableDirectionDefault) {
        view.selectedView.alpha = 0;
    }
    
    if (draggableDirection == YSLDraggableDirectionLeft) {
        view.selectedView.backgroundColor = RGB(215, 104, 91);
        view.selectedView.alpha = widthRatio > 0.8 ? 0.8 : widthRatio;
    }
    
    if (draggableDirection == YSLDraggableDirectionRight) {
        view.selectedView.backgroundColor = RGB(114, 209, 142);
        view.selectedView.alpha = widthRatio > 0.8 ? 0.8 : widthRatio;
    }
}

- (void)cardContainerViewDidCompleteAll:(YSLDraggableCardContainer *)container;
{
    NSLog(@"++ Did CompleteAll);
}

- (void)cardContainerView:(YSLDraggableCardContainer *)cardContainerView didSelectAtIndex:(NSInteger)index draggableView:(UIView *)draggableView
{
    NSLog(@"++ Tap card index : %ld",(long)index);
}

Undo

- (void)buttonTap:(UIButton *)button
{
    __weak ViewController *weakself = self;
    [_container movePositionWithDirection:YSLDraggableDirectionDown isAutomatic:YES undoHandler:^{
       UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@""
                                                                                message:@"Do you want to reset?"
                                                                         preferredStyle:UIAlertControllerStyleAlert];
            
       [alertController addAction:[UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [weakself.container movePositionWithDirection:YSLDraggableDirectionDown isAutomatic:YES];
       }]];
            
       [alertController addAction:[UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            [weakself.container movePositionWithDirection:YSLDraggableDirectionDefault isAutomatic:YES];
       }]];
            [self presentViewController:alertController animated:YES completion:nil];
    }];
}

Licence

MIT

Other Library

ysldraggablecardcontainer's People

Contributors

y-hryk avatar

Stargazers

Andrew Johnson avatar  avatar  avatar Leessang avatar JackerooChu avatar  avatar  avatar  avatar Bradley Danuser avatar Wely avatar Kheang Senghort avatar HanYY avatar Salar Soleimani avatar 霸霸 avatar Annie avatar  avatar  avatar LeverTsui avatar Kushal Panchal avatar Eason_zhou avatar  avatar Yongle-Fu avatar  avatar JarvenSun avatar Rocket avatar  avatar 时间shiwo avatar Az avatar Hardik Amal avatar pengchunliang avatar  avatar Prateek Sharma avatar Marcos Contente avatar  avatar Ken Tominaga avatar Tenloy avatar  avatar xeerlangd avatar Pratik avatar marskey avatar Jamhony_张 avatar 尚毛毛 avatar 皮蛋 avatar  avatar __status302 avatar Zhuo avatar  avatar Praveen Sharma avatar  avatar Hieu Bui avatar  avatar Edward Valentini avatar MudSang avatar  avatar Ben DiFrancesco avatar FanXiaobin avatar BigF avatar ChengRan avatar Cem Gültunca avatar  avatar 孙宁 avatar Zhihui avatar  avatar  avatar Ashwin Kumar avatar xiaoguang avatar Kien Lhi avatar Willing Guo avatar Ajeet Pratap Maurya avatar  avatar  avatar MISSAJJ琴瑟静听 avatar ritesh Kumar avatar  avatar  avatar wjiuxing avatar  avatar Paul J avatar Fernando Reynoso avatar 宋立君 avatar Darren Ou avatar  avatar Kai avatar thomas avatar liang avatar  avatar pany avatar Tofu avatar MacOMNI avatar ZhiHua avatar CoderHarry avatar Karim Sallam avatar 萧子然 avatar Richard Frank avatar  avatar  avatar Steven Koposov avatar  avatar Nihed Majdoub avatar  avatar

Watchers

Emmanuel Ay avatar James Cloos avatar MohsinAli avatar Umakanta Sahoo avatar  avatar Zihan Xu avatar Carabineiro avatar Kien Lhi avatar  avatar 孙宁 avatar  avatar Aryan Kashyap avatar  avatar

ysldraggablecardcontainer's Issues

Images are Streching?

Hi thanks for the Great library, But my images stretching when i assign to card view can you please help me how to add images with out stretching.

Regarding CardView height

Hi,

Excellent work with this framework. The only problem that I have is the height adjustment of the card. Can you suggest a way to not alter the card height once that is set from the view controllers?

Memory taken by cards is not being released after swiped

First of all, thank you for your nice library, I am using your library in the project I am working where in the project I am loading cards using the JSON response from my website. I have implemented a basic mechanism which will load 20 cards at a time and after they are swiped another 20 cards will be loaded from REST api. The issue is when cards are created they consume a small amount of memory for image in the card, and they memory is not being released when the card is swiped and removed from view, for about 50 cards swiped the memory consumption of the app increases to 400mb from 120mb. I think the memory taken by each cards is not released. What can I do to avoid this situation ?

没有复用机制

提一个建议:YSLCardView没有复用机制,可能造成展示大数量的cardview性能或者内存问题。可以模仿UITableView中对UITableViewCell的复用机制。

How to setup in storyboard?

I've taken uiview in storboard and given its class YSLCardView did all the things as per the demo but not able to achieve this functionality you did it programatically.

卡片不能循环滑动

当滑到最后一张图片的时候 怎么让最后一张图片和第一张完美衔接 不会出现再次创建的效果

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.