ios 购物车商品下落动画
2018-01-15 11:09
316 查看
属性:
@property (nonatomic,strong) NSMutableArray *animationLayers;
@property (nonatomic,
assign) BOOL isNeedNotification;
@property (nonatomic,
assign) BOOL isAnimating;
方法:
- (void)addProductsAnimati4000
on:(UIImageView *)imageView dropToPoint:(CGPoint)dropToPoint isNeedNotification:(BOOL)isNeedNotification
{
//若正在做动画,就结束,防止连续点击
if (self.isAnimating) {
// return;
}
self.isAnimating =
YES;
self.isNeedNotification = isNeedNotification;
if (self.animationLayers ==
nil) {
self.animationLayers = [[NSMutableArray
alloc] init];
}
CGRect frame = [imageView
convertRect:imageView.bounds
toView:APPDELEGATE.window];
CALayer *transitionLayer = [[CALayer
alloc] init];
transitionLayer.frame = frame;
transitionLayer.contents = imageView.layer.contents;
[APPDELEGATE.window.layer
addSublayer:transitionLayer];
[self.animationLayers
addObject:transitionLayer];
CGPoint point1 = transitionLayer.position;
CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation
animationWithKeyPath:@"position"];
CGMutablePathRef path =
CGPathCreateMutable();
CGPathMoveToPoint(path,
nil, point1.x, point1.y);
CGPathAddCurveToPoint(path,
nil, point1.x, point1.y -
30, dropToPoint.x, point1.y -
30, dropToPoint.x, dropToPoint.y);
positionAnimation.path = path;
CABasicAnimation *opacityAnimation = [CABasicAnimation
animationWithKeyPath:@"opacity"];
opacityAnimation.fromValue =
@1;
opacityAnimation.toValue =
@0.9;
CABasicAnimation *transformAnimation = [CABasicAnimation
animationWithKeyPath:@"transform"];
transformAnimation.fromValue = [NSValue
valueWithCATransform3D:CATransform3DIdentity];
transformAnimation.toValue = [NSValue
valueWithCATransform3D:CATransform3DScale(CATransform3DIdentity,
0.2,
0.2, 1)];
CAAnimationGroup *groupAnimation = [CAAnimationGroup
animation];
groupAnimation.animations =
@[positionAnimation, transformAnimation, opacityAnimation];
groupAnimation.duration =
0.5;
groupAnimation.delegate
= self;
groupAnimation.fillMode =
kCAFillModeForwards;
groupAnimation.removedOnCompletion =
YES;
[transitionLayer addAnimation:groupAnimation
forKey:@"cartParabola"];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
self.isAnimating =
NO;
if (self.animationLayers.count
> 0) {
CALayer *layer =
self.animationLayers[0];
layer.hidden =
YES;
[layer removeFromSuperlayer];
[self.animationLayers
removeObjectAtIndex:0];
[APPDELEGATE.window.layer
removeAnimationForKey:@"cartParabola"];
if (self.isNeedNotification) {
[[NSNotificationCenter
defaultCenter] postNotificationName:@"shopCarAnimationEnd"
object:nil];
}
// if (_addShopCarFinished) {
// self.addShopCarFinished();
// }
}
}
调用:
[selfaddProductsAnimation:self.goodImage
dropToPoint:CGPointMake(Width *
0.625,
Height - 50)
isNeedNotification:YES];
相关文章推荐
- 学习笔记之——EventBus实现全局加减购物车商品(动画)
- iOS添加到购物车的简单动画效果
- iOS手机淘宝加入购物车动画分析
- 把商品添加到购物车的动画效果(贝塞尔曲线)
- iOS添加购物车动画效果示例
- iOS添加到购物车的简单动画效果
- 动画加商品详情加商品购物车
- 购物车增加、减少商品时动画效果:jQuery.Fly.js插件使用方法
- 仿京东IOS APP商品详情页购物车栏悬浮底部
- iOS手机淘宝加入购物车动画分析
- iOS 仿淘宝加入购物车前选择尺寸,规格弹窗的向内凹陷折叠动画效果和标签流布局
- 组合属性动画+商品详情+MVP+购物车
- ios 添加到购物车的动画
- iOS实现自定义购物车角标显示购物数量(添加商品时角标抖动 Vie)
- iOS 购物车动画
- iOS开发仿淘宝添加到购物车的动画效果实现
- iOS 动画之购物车 贝塞尔曲线
- 把商品添加到购物车的动画效果(贝塞尔曲线)
- 动画效果第一弹——购物车添加商品特效
- IOS 加入购物车动画