今天带来的是仿百度外卖,饿了么-点餐效果既物品加入购物车时的动画效果,这里用的Masonry布局,下滑的效果主要是通过UIBezierPath CAKeyframeAnimation CABasicAnimation以及CAAnimationGroup实现的

因为写的比较匆忙 注释不是很多,而且界面用的都是色块,只能将就着看了.....
下面蓝色的 button 也是会动的,由于没做 gif 图,就只能用截图将就着看了,代码如下
首先是 自定义cell
//
//  MyTableViewCell.h
//  仿百度外卖-点餐效果
//
//  Created by Amydom on 16/12/5.
//  Copyright © 2016年 Amydom. All rights reserved.
//#import <UIKit/UIKit.h>
//block 用于响应 cell 上 button 点击方法
typedef void (^btnPulsBlock)(NSInteger count , BOOL animated);@interface MyTableViewCell : UITableViewCell@property (nonatomic, strong) UIImageView *foodImage;   // cyan
@property (nonatomic, strong) UILabel *nameLabel;       // orange
@property (nonatomic, strong) UILabel *priceLabel;      // gray
@property (nonatomic, strong) UIButton *btnMinus;       // black
@property (nonatomic, strong) UIButton *btnPlus;        // black
@property (nonatomic, strong) UILabel *orderCount;      // red
@property (nonatomic, copy)   btnPulsBlock block;       // block
@property (nonatomic, strong) UIImageView *animateView; // 购物车图标
@property (nonatomic, assign) NSInteger numCount;       // 计数器@end
//
//  MyTableViewCell.m
//  仿百度外卖-点餐效果
//
//  Created by Amydom on 16/12/5.
//  Copyright © 2016年 Amydom. All rights reserved.
//#import "MyTableViewCell.h"
#import "Masonry.h"@implementation MyTableViewCell- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];if (self) {[self createSubviews];}return self;
}- (void)createSubviews
{//因为采用懒加载,所以用 self 走控件的 getter 方法[self.contentView addSubview:self.foodImage];[self.contentView addSubview:self.nameLabel];[self.contentView addSubview:self.priceLabel];[self.contentView addSubview:self.btnMinus];[self.contentView addSubview:self.btnPlus];[self.contentView addSubview:self.orderCount];
}
//懒加载
- (UIImageView *)foodImage
{if (!_foodImage) {_foodImage = [[UIImageView alloc] init];}return _foodImage;
}
- (UILabel *)nameLabel
{if (!_nameLabel) {_nameLabel = [[UILabel alloc] init];}return _nameLabel;
}
- (UILabel *)priceLabel
{if (!_priceLabel) {_priceLabel = [[UILabel alloc] init];}return _priceLabel;
}
- (UIButton *)btnMinus
{if (!_btnMinus) {_btnMinus = [UIButton buttonWithType:UIButtonTypeCustom];}return _btnMinus;
}
- (UIButton *)btnPlus
{if (!_btnPlus) {_btnPlus = [UIButton buttonWithType:UIButtonTypeCustom];}return _btnPlus;
}
- (UILabel *)orderCount
{if (!_orderCount) {_orderCount = [[UILabel alloc] init];}return _orderCount;
}//进行布局(由于animate 会使控件发生变化,所以在layoutSubviews里进行正式的布局)
- (void)layoutSubviews{[super layoutSubviews];[self.foodImage mas_makeConstraints:^(MASConstraintMaker *make) {//上make.top.equalTo(self.contentView.mas_top).with.offset(5.0);//左make.left.equalTo(self.contentView.mas_left).with.offset(5.0);//宽make.width.equalTo(@88.0);//高make.height.equalTo(@88.0);}];self.foodImage.backgroundColor = [UIColor cyanColor];[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {//左距离 foodimage 右的距离make.left.equalTo(_foodImage.mas_right).with.offset(5.0);make.top.equalTo(self.contentView.mas_top).with.offset(5.0);make.right.equalTo(self.contentView.mas_right).with.offset(-5.0);make.height.equalTo(@30);}];self.nameLabel.backgroundColor = [UIColor orangeColor];[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {//左,与_nameLabel一样make.left.equalTo(_nameLabel);make.width.equalTo(@50);make.height.equalTo(@30);//下make.bottom.equalTo(self.contentView.mas_bottom).with.offset(-5);}];self.priceLabel.backgroundColor = [UIColor lightGrayColor];[self.btnMinus mas_makeConstraints:^(MASConstraintMaker *make) {//x轴中心make.centerX.equalTo(_nameLabel);//y 轴中新make.centerY.equalTo(self.contentView);//长 宽make.width.height.mas_equalTo(CGSizeMake(25, 25));}];self.btnMinus.backgroundColor = [UIColor blackColor];[self.orderCount mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(_btnMinus.mas_right).with.offset(10);make.centerY.equalTo(self.contentView);make.width.height.mas_equalTo(CGSizeMake(35, 25));}];self.orderCount.backgroundColor = [UIColor redColor];[self.btnPlus mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(_orderCount.mas_right).with.offset(10);make.centerY.equalTo(self.contentView);make.width.height.mas_equalTo(CGSizeMake(25, 25));}];self.btnPlus.backgroundColor = [UIColor blackColor];[_btnMinus setTitle:@"减" forState:UIControlStateNormal];[_btnMinus addTarget:self action:@selector(clickMin:) forControlEvents:UIControlEventTouchUpInside];[_btnPlus setTitle:@"加" forState:UIControlStateNormal];[_btnPlus addTarget:self action:@selector(clickPuls:) forControlEvents:UIControlEventTouchUpInside];}//btn 点击方法(加)
- (void)clickPuls:(UIButton *)btn{self.numCount += 1;self.block(self.numCount , YES);[self showOrderNums:self.numCount];}
//btn 点击方法(减)
- (void)clickMin:(UIButton *)btn
{self.numCount -= 1;self.block(self.numCount, NO);[self showOrderNums:self.numCount];
}//显示数量
-  (void)showOrderNums : (NSInteger)numCount{self.orderCount.text = [NSString stringWithFormat:@"%ld",(long)numCount];}- (void)awakeFromNib {[super awakeFromNib];// Initialization code
}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {[super setSelected:selected animated:animated];// Configure the view for the selected state
}@end


这里是 controller
//
//  ViewController.h
//  仿百度外卖-点餐效果
//
//  Created by Amydom on 16/12/5.
//  Copyright © 2016年 Amydom. All rights reserved.
//#import <UIKit/UIKit.h>@interface ViewController : UIViewController@end
//
//  ViewController.m
//  仿百度外卖-点餐效果
//
//  Created by Amydom on 16/12/5.
//  Copyright © 2016年 Amydom. All rights reserved.
//#import "ViewController.h"
#import "MyTableViewCell.h"
#import "shopCartView.h"@interface ViewController ()<CAAnimationDelegate , UITableViewDelegate , UITableViewDataSource>{CGFloat _endPoint_x;CGFloat _endPoint_y;UIBezierPath *_path;CALayer *_dotLayer;}@property (nonatomic , strong)shopCartView *shopCartView;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];self.view.backgroundColor = [UIColor whiteColor];UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];tableView.delegate = self;tableView.dataSource = self;[tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"MyTableViewCell"];[self.view addSubview:tableView];_shopCartView = [[shopCartView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 100 , self.view.frame.size.width, 100)];_shopCartView.backgroundColor = [UIColor lightGrayColor];[self.view addSubview:_shopCartView];}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 10;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *indetifier = @"MyTableViewCell";MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indetifier];//block 回调__weak __typeof(& *cell) weakCell = cell;//防止循环引用cell.block = ^(NSInteger nCount , BOOL boo){CGRect parentRect = [weakCell convertRect:weakCell.btnPlus.frame toView:self.view];if (boo) {// 这里是动画开始的方法[self JoinCartAnimationWithRect:parentRect];}else{}};return cell;}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{return 100;}#pragma mark - animated
//加入购物车动画
-(void) JoinCartAnimationWithRect:(CGRect)rect{//紫色小方块结束点_endPoint_x = 35;_endPoint_y = self.view.frame.size.height - 35;//紫色小方块开始点CGFloat startX = rect.origin.x;CGFloat startY = rect.origin.y;//绘制贝塞尔曲线_path = [UIBezierPath bezierPath];[_path moveToPoint:CGPointMake(startX, startY)];//三点曲线--既让紫色小方块的下滑线路[_path addCurveToPoint:CGPointMake(_endPoint_x, _endPoint_y) controlPoint1:CGPointMake(startX, startY) controlPoint2:CGPointMake(startX - 180, startY - 200)];//下滑时的紫色小方块_dotLayer = [CALayer layer];_dotLayer.backgroundColor = [UIColor purpleColor].CGColor;_dotLayer.frame = CGRectMake(0, 0, 20, 20);_dotLayer.cornerRadius = 5;[self.view.layer addSublayer:_dotLayer];[self groupAnimation];
}#pragma mark - 组合动画
-(void)groupAnimation{CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];animation.path = _path.CGPath;animation.rotationMode = kCAAnimationRotateAuto;CABasicAnimation *alphaAnimation = [CABasicAnimation animationWithKeyPath:@"alpha"];alphaAnimation.duration = 0.5f;alphaAnimation.fromValue = [NSNumber numberWithFloat:1.0];alphaAnimation.toValue = [NSNumber numberWithFloat:0.1];alphaAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];CAAnimationGroup *groups = [CAAnimationGroup animation];groups.animations = @[animation,alphaAnimation];groups.duration = 0.8f;groups.removedOnCompletion = NO;groups.fillMode = kCAFillModeForwards;groups.delegate = self;[groups setValue:@"groupsAnimation" forKey:@"animationName"];[_dotLayer addAnimation:groups forKey:nil];[self performSelector:@selector(removeFromLayer:) withObject:_dotLayer afterDelay:0.8f];
}- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{if ([[anim valueForKey:@"animationName"]isEqualToString:@"groupsAnimation"]) {CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];shakeAnimation.duration = 0.25f;shakeAnimation.fromValue = [NSNumber numberWithFloat:0.9];shakeAnimation.toValue = [NSNumber numberWithFloat:1];shakeAnimation.autoreverses = YES;// 这里是下方的自定义View上面 放的btn.[_shopCartView.btnBackImg.layer addAnimation:shakeAnimation forKey:nil];}
}
//移除layer动画
- (void)removeFromLayer:(CALayer *)layerAnimation{[layerAnimation removeFromSuperlayer];
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}@end

注:

_shopCartView 这个里面 其实就是放了一个 button 别的什么都没写,可以根据自己的需要用自定义 view 或者直接在 Controller 里随便写一个就行
由于时间比较紧,所以写的比较糙,还有可以优化的地方,大家可以根据自己的需要进行修改!!

iOS 仿百度外卖,饿了么-点餐效果(加入购物车效果)相关推荐

  1. iOS 仿百度外卖,饿了么-商品列表页

    今天带来的是仿百度外卖的商品列表页 下载地址 先看下效果图 这个主要是通过 - (void)selectRowAtIndexPath:(nullableNSIndexPath *)indexPath ...

  2. android 仿饿了么地图,iOS Andriod百度地图仿百度外卖 饿了么 选择我的地址 POI检索...

    title: iOS Andriod百度地图仿百度外卖 饿了么 选择我的地址 POI检索 date: 2015-09-19 21:06:26 tags: 百度外卖选择送货地址:饿了么选择送货地址: 第 ...

  3. iOS仿美团外卖饿了吗App点餐动画

    前言: 在这篇文章中你可以学到什么? Masonry布局, Block 以及动画, 俗称的懒加载. (想了解的看一看). 0.- tableViewCell布局篇–为方便大家查看, 我会尽量贴出全部代 ...

  4. android仿百度外卖波浪_头像随波浪漂浮效果—仿Android百度外卖

    前几天看到有iOS仿百度外卖的个人页,所以就随手撸了个Android.效果图如下: demo.gif 源码 改造轮子 轮子就不重复造了,github上已经有实现波浪的效果WaveView,WaveVi ...

  5. CSS3高仿百度外卖头像波浪效果

    好Q啼的头像,说好的波浪捏,浪到哪里去了,别急,静静欣赏动态效果:链接:https://pan.baidu.com/s/1gfAM3y7 密码:wxn6 技术: 1.css water wave 实现 ...

  6. 仿百度外卖的酷炫水波纹效果

    2019独角兽企业重金招聘Python工程师标准>>> 我们先来看下这个自定义的View的代码是如何实现的. 我们一步步来分析.首先我们要自定义一个View. 自定义View流程 我 ...

  7. 仿百度外卖、美团外卖、淘点点等左右联动ListView菜单展示

         !!之前代码有问题,左边Listview项滚出屏幕后位置不对,没有联动,重新改了下,https://github.com/wpq2014/MyDemo 相关文章:http://www.jia ...

  8. Android:高仿百度外卖、美团、淘点点二级联动效果!

    美团,百度外卖的左右二级联动效果如下: 具体的效果建议打开手机软件玩玩. 分析 首先我们一起分析一下这个界面给我们要怎么去实现. 1.最上面的ToolBar不用多解释,比较简单. 2.下面三个界面切换 ...

  9. android仿百度外卖波浪_iOS实现百度外卖头像波浪的效果

    效果演示 百度外卖 波浪效果图: 你需要知道的 CADisplayLink 简单的说就是一定时器,其根本利用刷帧和屏幕频率一样来重绘渲染页面. 其创建方式: CADisplayLink *timer ...

最新文章

  1. mysql事件探查器_【干货】Mysql的事件探查器-之Mysql-Proxy代理实战一(安装部署与实战sql拦截与性能监控)...
  2. java一个接口执行结束释放内存_java的灵魂--JVM虚拟机
  3. POJ 1637 Sightseeing tour(最大流)
  4. SQL Server数据库中使用sql脚本删除指定表的列
  5. MKNetWorkKit使用方法
  6. java 代码 _程序员用1.5小时写出的Java代码,让同事瞠目结舌!直呼优秀
  7. NOI图论算法:二分图匹配
  8. 一个WordPress站点绑定多个域名
  9. canal java_易用的 canal java 客户端 canal-client
  10. 华为P10的内存门和闪存门的检测方法
  11. 【模糊神经网络】基于matlab的模糊神经网络仿真
  12. python编码器用什么意思_通常提到的编码器是干什么用的
  13. Linux入门学习教程:在Ubuntu 14.04中安装使用搜狗拼音输入法
  14. Windows便签数据恢复
  15. Go语言grpc proto生成pb文件
  16. Java计算同比环比
  17. Python学习之Craps赌博游戏篇
  18. 如何搭建WordPress个人博客网站?
  19. 值得收藏的JavaScript代码
  20. Nginx:屏蔽 IP

热门文章

  1. jenkins + gitlab 自动化构建全流程记录。
  2. GD32F4(9):GD32f4出现上电不工作,必须按复位程序才能跑起来
  3. one's complement two's complement【待考究】
  4. E-mark认证审核工作的重要性
  5. 财务自由之路——为什么选择淘宝(上)
  6. 怎么才能学好CNC数控编程
  7. scrapy的入门使用
  8. 现在做哪个行业好赚钱
  9. Excel 多个数和为定数的随机数生成方式
  10. nandflash yaffs2 oob