美文网首页iOS技术iOS学习笔记iOS Developer
iOS之商品飞入购物车动画效果

iOS之商品飞入购物车动画效果

作者: smile丽语 | 来源:发表于2016-08-26 14:50 被阅读1500次

对于电商APP产品,购物车这块还是很多细节的,这不,我们的产品大大提出,需要用户点击商品时飞入购物车的动画特效。

动画.gif

这就是我的demo的动画效果,暂时并没有做UI美观处理,仅仅展示功能,如果觉得还可以,可以接着向下看喽。

1、先把动画效果自定义

这里路径和缩放效果及动画时间可以根据自己的需求进行更改,有需要直接拿走不谢!
.h文件:

//  商品动画进入购物车效果

#import <UIKit/UIKit.h>

@interface UIView (Animation)
- (void)animationStartPoint:(CGPoint)start endPoint:(CGPoint)end didStopAnimation:(void(^)(void)) event;
@end

.m文件:

#import "UIView+Animation.h"
#import <objc/message.h>

@interface UIView ()

@property (nonatomic, copy) void (^animStop)(void);

@end

@implementation UIView (Animation)

- (void)animationStartPoint:(CGPoint)start endPoint:(CGPoint)end didStopAnimation:(void (^)(void))event {
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:start];
    [path addCurveToPoint:end controlPoint1:start controlPoint2:CGPointMake(start.x, start.y)];
    
    // 路径
    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.path = path.CGPath;
    animation.rotationMode = kCAAnimationRotateAuto;
    
    // 缩放
    CABasicAnimation *scAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scAnimation.fromValue = @1;
    scAnimation.toValue = @0.2;
    scAnimation.autoreverses = YES;
    
    CAAnimationGroup *groups = [CAAnimationGroup animation];
    groups.animations = @[animation,scAnimation];
    groups.duration = 0.5; // 时间
    groups.removedOnCompletion = NO;
    groups.fillMode = kCAFillModeForwards;
    groups.delegate = self;
    [groups setValue:@"groupsAnimation" forKey:@"animationName"];
    [self.layer addAnimation:groups forKey:nil];
    
    self.animStop = event;
    
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
   self.animStop();
}

- (void)setAnimStop:(void (^)(void))animStop {
    objc_setAssociatedObject(self, @"animStop", animStop, OBJC_ASSOCIATION_COPY);
}

- (void (^)(void))animStop {
    return objc_getAssociatedObject(self, @"animStop");
}

@end

2、在你所需要使用动画效果的控制器里操作

引入头文件#import "UIView+Animation.h"
找到点击当前的item的方法,我这里是collectionView,

#pragma mark collectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
  // 1.获取数据模型
  YYPGoodsModel *good = self.goods[indexPath.item];
  self.listVC.model = good;
        
  // 2.获取 item 创建当前imageView
  UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
  UIImageView *imageView = [[UIImageView alloc] init];
  [imageView sd_setImageWithURL:[NSURL URLWithString:good.img] placeholderImage: [UIImage imageNamed:@"u58"]];
   
  // 计算坐标系
  CGFloat y = cell.y - self.collectView.contentOffset.y;
  imageView.frame = cell.frame;
  imageView.y = y;imageView.backgroundColor = [UIColor clearColor];
  [self.view addSubview:imageView];
    
  // 3.商品飞入购物车后移除当前imageView
  [imageView animationStartPoint:imageView.center endPoint:self.cartBtn.center didStopAnimation:^{
      [imageView removeFromSuperview];
  }];

}

对于电商产品的购物车设计,一些其他细节你注意了吗?请参考这篇文章,本人真心觉得很不错
http://www.cocoachina.com/design/20160217/15302.html

相关文章

  • iOS之商品飞入购物车动画效果

    对于电商APP产品,购物车这块还是很多细节的,这不,我们的产品大大提出,需要用户点击商品时飞入购物车的动画特效。 ...

  • 商品飞入购物车效果(pc端)

    如果用Jquery之类的动画很难做出抛物线的效果,所以有大神就开发出来了封装的抛物线运动的插件parabola.j...

  • 加入购物车动画

    需求: 点击商品列表中正在售卖的商品,通过坐标转换和动画的方式,完成类似点赞动画、加入购物车、查看头像大图等效果。...

  • vue实现点击商品加入购物车动画

    如今这么发达,想必大家都用饿了么点过餐吧?当你选择商品加入购物车,小球飞入的动画是不是很炫酷?,大体是下边这个样子...

  • 购物车飞入动画

    动画原理 这里是利用物体在水平方向减速运动的同时也在垂直方向加速运动就可以实现抛物线运动轨迹,所以我们可以利用An...

  • 《Android APP可能有的东西》之UI篇:加入购物车动画

    很多电商app的加入购物车的动作会要求加上动画效果:飞进购物车,想来也合理,在listview界面时商品快速加入购...

  • 解决jquery animate动画效果出现的抖动

    起因:在做鼠标滑过商品缩略图,弹出“添加购物车”按钮的动画效果时,出现了动画闪烁的问题,后来发现是animate重...

  • 贝塞尔曲线、extern

    如何用贝塞尔曲线做一些商品添加到购物车的动画效果? 上面的效果它可以用 CAShapeLayer + UIBezi...

  • UIView动画合集

    iOS开发-UIView之动画效果的实现方法(合集) 前言:在开发APP中,我们会经常使用到动画效果。使用动画可以...

  • 贝塞尔曲线的应用(二)

    购物车添加商品实现轨迹动画 先看下实现效果 分析下实现原理,起始点是添加按钮,购物车是结束点,我们把控制点的x坐标...

网友评论

本文标题:iOS之商品飞入购物车动画效果

本文链接:https://www.haomeiwen.com/subject/hkczsttx.html