IOS 实现加入购物车的效果

iOS开发——仿淘宝添加到购物车的动画效果实现 类似于淘宝一样,我们在写一些购物、订餐之类的app的时候,在用户选择购买或者加入购物车时可以添加一个商品飞到购物车中的动画效果,如下图所示: 实现这个效果还是不算难的,但涉及的问题比较多,还是挺有学习价值的。主要面对的问题有以下几点 1、cell中有button,如何获得该button,即如何知道用户点击的是哪一个button。 2、坐标系的转换,这里频繁使用坐标系转换,主要原因是这里需要涉及三个视图——cell、tableView、view 3、Bezier曲线的应用。 下面我们一一来解决这些问题。 正好 阅读详情

代码示例:


 这是临时写的,代码粗糙,只希望能有所帮助吧!

//

//  WWCRootViewController.m

//  TestCAOrUIViewAnimationApp7-30

//

//  Created by Whitney.c on 15/7/30.

//  Copyright (c) 2015年 ZhongShan Sun union Medical Technology Co. Ltd. All rights reserved.

//


#import "WWCRootViewController.h"


@interface WWCRootViewController ()


@end


@implementation WWCRootViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    NSLog(@"viewDidLoad ... ");

    

    self.view.backgroundColor = [UIColor whiteColor];

    

    //[self loadSelfLayoutSubViews];

}




-(void)loadView

{

    [super loadView]; 

    

    

    [self loadSelfLayoutSubViews];

}



-(void)loadSelfLayoutSubViews

{

    

    // 加入购物车的按钮

    btn = [UIButton buttonWithType:UIButtonTypeCustom];

    btn.frame = CGRectMake(20, 80, 100, 35);

    [btn setTitle:@"$900.99" forState:UIControlStateNormal];

    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

    [btn addTarget:self action:@selector(addGodToMarket:) forControlEvents:UIControlEventTouchUpInside];

    [btn setBackgroundColor:[UIColor grayColor]];

    [btn.titleLabel setFont:[UIFont systemFontOfSize:12]];

    [self.view addSubview:btn];

    

    

    // 购物车

    

    

    cartImgV = [[UIImageView alloc] init];

    cartImgV.image = [UIImage imageNamed:@"cart_empty"];

    cartImgV.backgroundColor = [UIColor clearColor];

    cartImgV.frame = CGRectMake(250, 500, 35, 35);

    

    [self.view addSubview:cartImgV];

    

}


-(void)addGodToMarket:(UIButton*)bt

{

    NSString *price =  bt.titleLabel.text ;

    NSLog(@"price : %@" ,price);

    

    // 加入购物车动画效果

    

    CALayer *transitionLayer = [[CALayer alloc] init];

    [CATransaction begin];

    [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

    transitionLayer.opacity = 1.0;

    transitionLayer.contents = bt.titleLabel.layer.contents;

    transitionLayer.frame = [[UIApplication sharedApplication].keyWindow convertRect:bt.titleLabel.bounds fromView:bt.titleLabel];

    [[UIApplication sharedApplication].keyWindow.layer addSublayer:transitionLayer];

    [CATransaction commit]; // 提交动画

    

    

    // 路径曲线

    UIBezierPath *movePath = [UIBezierPath bezierPath];

    [movePath moveToPoint:transitionLayer.position];

    CGPoint toPoint = CGPointMake(cartImgV.center.x, cartImgV.center.y);

    [movePath addQuadCurveToPoint:toPoint controlPoint:CGPointMake(cartImgV.center.x

                                                                   , transitionLayer.position.x-100)];

    

    //关键帧

    CAKeyframeAnimation *positionAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    positionAnimation.path = movePath.CGPath;

    positionAnimation.removedOnCompletion = YES;

    

    CAAnimationGroup *group = [CAAnimationGroup animation];

    group.beginTime = CACurrentMediaTime();

    group.duration = 0.6;

    group.animations = [NSArray arrayWithObjects:positionAnimation, nil];

    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    group.delegate = self;

    group.fillMode = kCAFillModeForwards;

    group.removedOnCompletion = NO;

    group.autoreverses = NO;

    

    

    [transitionLayer addAnimation:group forKey:@"opacity"];

    

    [self performSelector:@selector(addCartFinished:) withObject:transitionLayer afterDelay:0.6f];

}


-(void)addCartFinished:(CALayer*)transitionLayer

{

    transitionLayer.opacity = 0; // 透明

    

}



- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end



iOS 加入购物车动画 前段时间做了一个商城类的项目,刚好用到加入购物车的动画效果,从网上找了个demo,优化了一下,很多参数可以自己配置,效果还是很不错的。 立即下载

相关推荐

ios-添加购物车动画.zip

模仿饿了么等软件的添加至购物车方法

iOS 添加到购物车 小动画

-(void)touchesBegan:(NSSetUITouch *> *)touches withEvent:(UIEvent *)event{     int y = 1 +  (arc4random() % 8);     int width = 20 +  (arc4random() % 100);     NSInteger x = 0 + (arc4random()

疯狐狸的博客 658

ios-加入购物车 动画.zip

加入购物车小动画

XZ_iOS 之 加入购物车bounce效果实现

效果图: 动画类XZAddToCartAnimation 的实现: import UIKit import Foundation let screenWidth = UIScreen.main.bounds.size.width let screenHeight = UIScreen.main.bounds.size.height class XZAddToCartAnimati...

understand_XZ的博客 345

ios 几句代码实现购物车功能 直接可用

说明 这是一个具备常规功能并方便改造的购物车模型 一共包含五个模块: * `GBShopcartViewController`: 购物车控制器 负责协调Model和View 只有100多行代码 * `GBShopcartFormat`: 负责网络请求与逻辑处理 * `GBShopcartTableViewProxy`: 作为控制器里边TableView的代理 * `View`: 包括Cell、HeaderView、CountView(改变商品数的视图)、BottomView(控制器底部包含结算按钮的视图) * `Model`: 包含BrandModel和ProductModel两层 ## 使用 首先将工程里边的JVShopcart文件夹拖入你的项目 然后就是开源库Vendor文件夹根据需求处理 Model是一定会改的 但是购物车的Model大同小异 其他的改动不会太大

ios--tableview加入购物车飞入效果

ios--tableview加入购物车飞入效果;

iOS--- 实现加入购物车的效果

代码示例:  这是临时写的,代码粗糙,只希望能有所帮助吧! // //  WWCRootViewController.m //  TestCAOrUIViewAnimationApp7-30 // //  Created by Whitney.c on 15/7/30. //  Copyright (c) 2015年 ZhongShan

iotjin的专栏 570

仿美团、饿了么加入购物车以及加入购物车动画

仿美团、饿了么加入购物车以及加入购物车动画;可自定义话动画样式

iOS 商品旋转加入购物车动画,并附带抖动效果

最近在开发一个商城类app,需要一个加入购物车一个动画效果,自己写会很麻烦,我就在网上找了一些资料最后实现了想要的效果,这个实现主要就是iOS提供的动画库:CAAnimation 实现效果如下: 下面就是实现代码,只有一个类PurchaseCarAnimationTool .h文件 typedef void (^animationFinisnBlock)(BOOL finish); #define ScreenWidth [UIScreen mainScreen].bounds.size.wi

WangQingLei0307的博客 811

ios-购物车简单实现.zip

一个简单的购物车实现,可计算全选和未全选状态下的金额。代码简单易懂。

ios-仿淘宝点击加入购物车前选择尺码、颜色信息的弹出视图.zip

仿淘宝点击加入购物车前选择尺码、颜色信息的弹出视图,尺码、颜色分类、库存等信息我是写死的数据,应该从服务器获取这些信息,没有服务器就将就下,纯代码编写,有需要的直接粘贴复制即可,改变数据源就可以了,选择尺码或者颜色任意选项后会根据该选项库存是否为0,确定某些选项不可选,淘宝这个页面的商品图片还可以点击看大图,长按保存图片,网上这类代码很多,我就不往里嵌入了,有需要的自行嵌入吧,本人代码风格不好,如不喜欢可以参照思路

IOS-购物车动画效果(图片移动)

代码为从左边图片抛物线投掷到右下角购物车动画,同理改动即可,渣代码见谅 // // ViewController.m // 动画 // // Created by Jack on 15-5-25. // Copyright (c) 2015年 Jack. All rights reserved. // #import "ViewController.h" @interface Vie

pycbingshen的博客 1337

解决Android UVCCamera stopPreview 报错 崩溃 闪退 问题

在使用libuvccamera库的UVCCamera时,经常在调用stopPreview关闭预览的时候,app直接崩溃闪退了,经过综合各种修改源码的方案,已解决这个问题,以下请参考: 首先找到android_usbfs.c,linux_usbfs.c两个原文件,在两个文件中都可以找到这段代码,按如下示例修改: 修改前: for (i = 0; i < num_urbs; i++) { if (urb == tpriv->iso_urbs[i]) { urb_idx = i + 1;

hanye2020的博客 3576

IOS 加入购物车动画

加入购物车动画   (在iOS代码库中浏览本帖) 关键字:购物车代码类库:视图动画(ViewAnimation)GitHub链接:https://github.com/wangluhui/shopCartDemo 将商品动画形式加入购物车,当商品进入购物车时,购物车有上下抖动效果,商品数量渐变。 测试环境:Xcode 6.2,iOS 6.0以上

枫岭晚 590

(赛事-2022)[re:Invent 2018]-002:通过分析log多次迭代优化奖励函数后- 最快7.6s / 圈

Deepracer training 流程

Rainbow 4711

生成式引擎优化(GEO)的概念与技术路径

生成式引擎优化(GEO)是针对生成式AI引擎的新型优化策略,旨在提升内容在AI搜索与问答平台中的可见性和可信度。与传统SEO相比,GEO更注重语义理解、知识图谱和多模态生成等技术,通过优化内容的结构化和平台适配性,使品牌信息在生成式AI中更易被采纳和呈现。其核心技术包括语义理解、向量数据库和实时反馈优化等,应用于品牌传播、智能客服和个性化推荐等领域。随着AI技术发展,GEO将向智能化、自动化方向演进,成为内容优化的重要工具。

Baixue5209的博客 1047

swift-商品加入购物车动画

// MARK: - 商品图片抛入购物车的动画效果 extension QHGoodListViewController { /** 开始动画 - parameter rect: 商品图标对象的frame - parameter iconView: 商品图标对象 */ private func startAnimation(rect:

FIGHTING的专栏 1512

如何实现三种不同RAM?(单端口RAM、伪双端口RAM、真双端口RAM|verilog代码|Testbench|仿真结果)

RAM(随机存取存储器)是计算机系统中的一种主要存储器件,用于存储和读取数据。在RAM中,单端口RAM(Single-port RAM)和双端口RAM(Dual-port RAM)是两种常见的类型,双端口RAM又分为真双端口(True dual-port RAM)和伪双端口RAM(Simple dual-port RAM)。那么什么是单端口和双端口?又该如何区分真双端口和伪双端口?输入只有一组数据线和一组地址线,读写共用地址线,输出只有一个端口。

Loudrs的博客 1万+

仿淘宝加入购物车动画

#pragma mark - 动画(加入购物车) - (void)shopBagAni { CGRect startRect; CGRect endRect; CGPoint imgPoint; //最右上角购物车图标位置 imgPoint = [self.view convertPoint:sizeView.img_dress.center fromVie

MinggeQingchun的博客 1411

Simplicity Studio V5与EFR32BG22蓝牙开发环境实战指南

本文详细介绍了Simplicity Studio V5集成开发环境与EFR32BG22蓝牙芯片的开发实战指南。内容涵盖开发环境安装、SDK配置、项目创建、调试烧录、外设驱动集成及常见问题解决方案,帮助开发者快速上手物联网蓝牙应用开发,并充分利用EFR32BG22的低功耗与高集成度特性。

v5w6x的博客 320

Windows 高精度计时器:QueryPerformanceCounter 原理、陷阱与最佳实践

本文深入解析Windows高精度计时器QueryPerformanceCounter(QPC)的工作原理、常见陷阱及最佳实践。QPC通过读取硬件计时器(如TSC)实现微秒级精度,适用于游戏开发、音视频处理等高性能场景。文章详细探讨了多核同步、动态频率调整等挑战,并提供了优化代码示例和性能对比数据。

weixin_33391446的博客 271

iOS一分钟搞定加入购物车的交互动画【转】

http://www.huangyibiao.com/archives/1294

qq_18183763的博客 276

基于YOLOv11的手术器械计数系统:从数据集构建到Web应用部署

m2cai16-tool数据集:包含15种腹腔镜手术器械的标注图像Cholec80数据集:包含80个胆囊切除手术视频,标注了7种器械SurgicalTools数据集:包含超过10,000张手术器械图像,涵盖21类常见器械手术剪(Scissors)止血钳(Hemostat)持针器(Needle Holder)手术刀(Scalpel)镊子(Forceps)拉钩(Retractor)吸引器(Suction)

YOLO 396

商品加入购物车的动画

额,做一个类似饿了吗加入购物车的动画 先说一下思路,再上代码吧 1.这里主要的难题就是坐标的计算,因为一个是tableView.supperView的坐标(购物车图标),还有一个就是cell中的起始图标, 思路:我的思路就是在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSI...

weixin_30321449的博客 186

无刷电机FOC硬件电路设计

本文先对MIT无刷电机FOC硬件电路分析做个简单的介绍,具体内容后续再更,其他模块可以参考去我其他文章软件程序在我另外一个博客【嵌入式–伺服电机】MIT无刷电机FOC驱动程序分析。

qq_35635374的博客 574

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

实现购物车动画

//加入购物车 步骤1 - (void)addToShopCar:(UIButton *)bt{ NSLog(@"1111"); //得到产品信息 UITableViewCell *cell = (UITableViewCell *)[bt superview]; NSIndexPath *indexPath = [mainTable indexPathForCel

JerryLeeFighting的专栏 790

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

上一篇: IOS TableView 根据子view 来获取当前Cell 方式
下一篇: IOS开发中 常用的宏定义[陆续更新]
dev-kevin
博客等级 码龄16年 3粉丝 27原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值