// MARK: - 商品图片抛入购物车的动画效果 extension QHGoodListVIEwController { /** 开始动画 - parameter rect: 商品图标对象的frame - parameter iconVIEw: 商品图标对象 */ private func startAnimation(rect: CGRect,iconVIEw:UIImageVIEw) { if layer == nil { layer = CALayer() layer?.contents = iconVIEw.layer.contents layer?.contentsGravity = kCAGravityResizeAspectFill layer?.bounds = rect layer?.cornerRadius = CGRectGetHeight(layer!.bounds)*0.5 layer?.masksToBounds = true layer?.position = CGPoint(x: iconVIEw.center.x,y: CGRectGetMinY(rect)+96) UIApplication.sharedApplication().keyWindow?.layer.addSublayer(layer!) path = UIBezIErPath() path!.movetoPoint(layer!.position) path?.addQuadCurvetoPoint(CGPoint(x: SCREEN_WIDTH - 25,y: 35),controlPoint: CGPoint(x: SCREEN_WIDTH*0.5,y: rect.origin.y - 80)) } // 组动画 groupAnimation() } // 组动画 帧动画抛入购物车 并放大、缩小图层增加点动效 private func groupAnimation() { // 开始动画禁用tableVIEw交互 tableVIEw.userInteractionEnabled = false // 帧动画 let animation = CAKeyframeAnimation(keyPath: "position") animation.path = path!.CGPath animation.rotationMode = kCAAnimationRotateauto // 放大动画 let bigAnimation = CABasicAnimation(keyPath: "transform.scale") bigAnimation.duration = 0.5 bigAnimation.fromValue = 1 bigAnimation.tovalue = 2 bigAnimation.timingFunction = camediatimingFunction(name: kcamediatimingFunctionEaseIn) // 缩小动画 let smallAnimation = CABasicAnimation(keyPath: "transform.scale") smallAnimation.beginTime = 0.5 smallAnimation.duration = 1.5 smallAnimation.fromValue = 2 smallAnimation.tovalue = 0.3 smallAnimation.timingFunction = camediatimingFunction(name: kcamediatimingFunctionEaSEOut) // 组动画 let groupAnimation = CAAnimationGroup() groupAnimation.animations = [animation,bigAnimation,smallAnimation] groupAnimation.duration = 2 groupAnimation.removedOnCompletion = false groupAnimation.fillMode = kCAFillModeForwards groupAnimation.delegate = self layer?.addAnimation(groupAnimation,forKey: "groupAnimation") } // 动画结束后做一些 *** 作 overrIDe func animationDIDStop(anim: CAAnimation,finished flag: Bool) { // 如果动画是我们的组动画 才开始一些 *** 作 if anim == layer?.animationForKey("groupAnimation") { // 开启交互 tableVIEw.userInteractionEnabled = true // 隐藏图层 layer?.removeAllAnimations() layer?.removeFromSuperlayer() layer = nil // 如果商品数大于0 显示购物车里地商品数量 if self.addGoodArray.count > 0 { addCountLabel.hIDden = false } // 商品数量渐出 let goodCountAnimation = CATransition() goodCountAnimation.duration = 0.25 addCountLabel.text = "\(self.addGoodArray.count)" addCountLabel.layer.addAnimation(goodCountAnimation,forKey: nil) //购物车颤抖 let cartAnimation = CABasicAnimation(keyPath: "transform.translation.y") cartAnimation.duration = 0.25 cartAnimation.fromValue = -5 cartAnimation.tovalue = 5 cartAnimation.autoreverses = true cartbutton.layer.addAnimation(cartAnimation,forKey: nil) } } }总结
以上是内存溢出为你收集整理的swift-商品加入购物车动画全部内容,希望文章能够帮你解决swift-商品加入购物车动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)