1、效果图

探探卡片视图切换效果 1

高仿探探的卡片视图切换效果,OC源代码免费下载 - 敏捷大拇指 - 探探卡片视图切换效果 1


探探卡片视图切换效果 2

高仿探探的卡片视图切换效果,OC源代码免费下载 - 敏捷大拇指 - 探探卡片视图切换效果 2





2、主要代码



2.1、CHCardView.h

[Objective-C] 纯文本查看 复制代码
#import <UIKit/UIKit.h>
@class CHCardView, CHCardItemView;
@protocol CHCardViewDelegate <NSObject>
@optional
- (void)cardView:(CHCardView *)cardView didClickItemAtIndex:(NSInteger)index;
@end

@protocol CHCardViewDataSource <NSObject>
@required
- (NSInteger)numberOfItemViewsInCardView:(CHCardView *)cardView;
- (CHCardItemView *)cardView:(CHCardView *)cardView itemViewAtIndex:(NSInteger)index;
- (void)cardViewNeedMoreData:(CHCardView *)cardView;
@optional
// default is equal to cardView's bounds
- (CGSize)cardView:(CHCardView *)cardView sizeForItemViewAtIndex:(NSInteger)index;

@end

@interface CHCardView : UIView
@property (nonatomic, weak) id <CHCardViewDataSource> dataSource;
@property (nonatomic, weak) id <CHCardViewDelegate> delegate;

- (void)deleteTheTopItemViewWithLeft:(BOOL)left;
- (void)reloadData;
@end




2.2、CHCardView.m

[Objective-C] 纯文本查看 复制代码
- (void)reloadData {

    if (_dataSource == nil) {
        return ;
    }
    // 1. 移除
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

    // 2. 创建
    _itemViewCount = [self numberOfItemViews];
    for (int i = 0; i < _itemViewCount; i++) {

        CGSize size = [self itemViewSizeAtIndex:i];

        CHCardItemView *itemView = [self itemViewAtIndex:i];
        [self addSubview:itemView];
        itemView.delegate = self;

        itemView.frame = CGRectMake(self.frame.size.width / 2.0 - size.width / 2.0, self.frame.size.height / 2.0 - size.height / 2.0, size.width, size.height);
        itemView.tag = i + 1;
        itemView.transform = CGAffineTransformMakeTranslation(self.frame.size.width +  500, 400);
        [UIView animateKeyframesWithDuration:0.15 delay:0.05 * i options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
            CGAffineTransform scaleTransfrom = CGAffineTransformMakeScale(1 - 0.005 * (10 - i), 1);
            itemView.transform = CGAffineTransformTranslate(scaleTransfrom, 0, 0.5 * (10 - i));
        } completion:nil];
        itemView.userInteractionEnabled = YES;
        [itemView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestHandle:)]];
    }
}




2.3、具体调用代码

[Objective-C] 纯文本查看 复制代码
if (panGest.state == UIGestureRecognizerStateChanged) {

        CGPoint movePoint = [panGest translationInView:self];
        _isLeft = (movePoint.x < 0);

        self.center = CGPointMake(self.center.x + movePoint.x, self.center.y + movePoint.y);

        CGFloat angle = (self.center.x - self.frame.size.width / 2.0) / self.frame.size.width * 0.5;
        _currentAngle = angle;
        self.transform = CGAffineTransformMakeRotation(angle);

        [panGest setTranslation:CGPointZero inView:self];

    } else if (panGest.state == UIGestureRecognizerStateEnded) {

        CGPoint vel = [panGest velocityInView:self];
        if (vel.x > 400 || vel.x < - 400) {
            [self remove];
            return ;
        }
        if (self.frame.origin.x + self.frame.size.width > 100 && self.frame.origin.x < self.frame.size.width - 100) {
            [UIView animateWithDuration:0.3 animations:^{
                self.center = _originalCenter;
                self.transform = CGAffineTransformMakeRotation(0);
            }];
        } else {
            [self remove];
        }
    }





3、下载

项目地址:

游客,如果您要查看本帖隐藏内容请回复


个人主页:

游客,如果您要查看本帖隐藏内容请回复