昨天用简书App的时候觉得这个View的弹出效果特别好,而且非常平滑,所以我就尝试写了一个,和简书App上的效果基本一致了:

下面开始讲解:

1.首先我们要知道这个页面有几个View?这个页面其实有四个View,self.view , 图中白色VC的View rootVC.view ,白色VC上的maskView maskView , 以及弹出的popView popView 。我们创建它们:

self.view.backgroundColor = [UIColor blackColor];

_popView = ({

UIView * popView = [[UIView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height /2.0)];

popView.backgroundColor = [UIColor grayColor];

//加个阴影

popView.layer.shadowColor = [UIColor blackColor].CGColor;

popView.layer.shadowOffset = CGSizeMake(0.5, 0.5);

popView.layer.shadowOpacity = 0.8;

popView.layer.shadowRadius = 5;

//关闭btn

UIButton * closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];

closeBtn.frame = CGRectMake(15, 0, 50, 40);

[closeBtn setTitle:@"关闭" forState:UIControlStateNormal];

[closeBtn setTitleColor:[UIColor colorWithRed:217/255.0 green:110/255.0 blue:90/255.0 alpha:1] forState:UIControlStateNormal];

[closeBtn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];

[popView addSubview:closeBtn];

popView;

});

//添加VC的View的方法

_rootVC.view.frame = self.view.bounds;

_rootVC.view.backgroundColor = [UIColor whiteColor];

_rootview = _rootVC.view;

[self addChildViewController:_rootVC];

[self.view addSubview:_rootview];

//rootVC上的maskView

_maskView = ({

UIView * maskView = [[UIView alloc]initWithFrame:self.view.bounds];

maskView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];

maskView.alpha = 0;

maskView;

});

[_rootview addSubview:_maskView];

2.然后要添加点击事件,这里为了方便我的弹出事件直接用的touchesBegan

- (void)show

{

[[UIApplication sharedApplication].windows[0] addSubview:_popView];

CGRect frame = _popView.frame;

frame.origin.y = self.view.frame.size.height/2.0;

[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

[_rootview.layer setTransform:[self firstTransform]];

} completion:^(BOOL finished) {

[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

[_rootview.layer setTransform:[self secondTransform]];

//显示maskView

[_maskView setAlpha:0.5f];

//popView上升

_popView.frame = frame;

} completion:^(BOOL finished) {

}];

}];

}

这里要注意一下的就是popview是添加到window上面的:[[UIApplication sharedApplication].windows[0] addSubview:_popView];

然后关键的layer形变方法来了

- (CATransform3D)firstTransform{

CATransform3D t1 = CATransform3DIdentity;

t1.m34 = 1.0/-900;

//带点缩小的效果

t1 = CATransform3DScale(t1, 0.95, 0.95, 1);

//绕x轴旋转

t1 = CATransform3DRotate(t1, 15.0 * M_PI/180.0, 1, 0, 0);

return t1;

}

- (CATransform3D)secondTransform{

CATransform3D t2 = CATransform3DIdentity;

t2.m34 = [self firstTransform].m34;

//向上移

t2 = CATransform3DTranslate(t2, 0, self.view.frame.size.height * (-0.08), 0);

//第二次缩小

t2 = CATransform3DScale(t2, 0.8, 0.8, 1);

return t2;

}

大家可以看到这,应该可以发现这里其实有两次形变

3.隐藏动画

- (void)close

{

_isShow = NO;

CGRect frame = _popView.frame;

frame.origin.y += self.view.frame.size.height/2.0;

[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

//maskView隐藏

[_maskView setAlpha:0.f];

//popView下降

_popView.frame = frame;

//同时进行 感觉更丝滑

[_rootview.layer setTransform:[self firstTransform]];

} completion:^(BOOL finished) {

[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

//变为初始值

[_rootview.layer setTransform:CATransform3DIdentity];

} completion:^(BOOL finished) {

//移除

[_popView removeFromSuperview];

}];

}];

}

最后,完整代码,已经封装好了,继承之后使用创建方法就行了

GitHub:Wzxhaha

https://github.com/Wzxhaha/WZXJianShuPopDemo

仿简书、淘宝等等App的View弹出效果相关推荐

  1. Android仿简书、淘宝等APP View弹出效果

    在用简书App的时候觉得这个View的弹出效果特别好,而且非常平滑. 先看看效果: 主要是scale,alpha,translation几个普通动画组合,这里不再分析. 实现效果图: 代码:https ...

  2. 淘宝首页之导航条——弹出式悬浮菜单

    昨天学习了布局,今天要来实现弹出式导航条.布局选的flex布局. 关于弹出式悬浮菜单总结了下大概是以下几步: 1.鼠标放到一级菜单上时二级菜单显示,鼠标移开二级菜单隐藏. 2.打算为二级菜单设置一个d ...

  3. HTML5响应式手机模板:电商网站设计——仿淘宝手机app界面模板源码 HTML+CSS+JavaScript...

    HTML5响应式手机模板:电商网站设计--仿淘宝手机app界面模板源码 HTML+CSS+JavaScript 手机电商模板 手机网站模板 企业手机网站模板 手机网站模板 手机模板 响应式手机网站 h ...

  4. HTML5响应式手机模板:电商网站设计——仿淘宝手机app界面模板源码 HTML+CSS+JavaScript

    HTML5响应式手机模板:电商网站设计--仿淘宝手机app界面模板源码 HTML+CSS+JavaScript 手机电商模板 手机网站模板 企业手机网站模板 手机网站模板 手机模板 响应式手机网站 h ...

  5. android 仿简书评论,Android 开发仿简书登录框可删除内容或显示密码框的内容

    简书App 是我很喜欢的一款软件.今天就模仿了一下他的登录框.先上图: 好了下面上代码,自定义ImgEditText 继承与EditText.重写一些方法. package lyf.myimgedit ...

  6. Android点击按钮显示密码,Android 开发仿简书登录框可删除内容或显示密码框的内容...

    简书App 是我很喜欢的一款软件.今天就模仿了一下他的登录框.先上图: 好了下面上代码,自定义ImgEditText 继承与EditText.重写一些方法. package lyf.myimgedit ...

  7. 高仿简书Android,高仿简书个人中心页面

    高仿简书个人中心页面 Demo下载地址: 先贴上效果图 1. 步骤 1.1 把APP的主题改为NoAction 1.2 引入Material Design 包 implementation 'com. ...

  8. 高仿简书个人中心页面

    高仿简书个人中心页面 Demo下载地址: 先贴上效果图 1. 步骤 1.1 把APP的主题改为NoAction <!-- Base application theme. --><st ...

  9. 使用SwipeRefreshLayout和RecyclerView实现仿“简书”下拉刷新和上拉加载更多

    原文地址: http://blog.csdn.net/leoleohan/article/details/50989549/ 一.概述 我们公司目前开发的所有Android APP都是遵循iOS风格设 ...

最新文章

  1. 剑指offer:面试题21. 调整数组顺序使奇数位于偶数前面
  2. BBC称中国人加班时间远超欧美:工作效率未必高
  3. get 和post 方式请求数据
  4. 华为修改优先级命令_VOlTE指标设定(华为网管各种命令)
  5. 进程间通信 - 邮槽实现
  6. 连续锁定2个不同的锁会死锁_研究死锁–第5部分:使用显式锁定
  7. HDU1232——通畅工程(并查集)
  8. myeclipse开发代码颜色搭配保护视力
  9. 服务器放行6in4协议,最简单的接入IPv6网络的方法 – 6in4隧道
  10. Windows 新漏洞可被用于强制服务器以攻击者身份认证,官方缓解措施已发布
  11. cin.get()和cin.getline()区别
  12. 数学归纳法与递归推演
  13. python自动获取北京时间_python将当前服务器的时区时间转为北京时间
  14. 颜色格式转换: 最简单的基于FFmpeg的libswscale的示例(YUV转RGB)
  15. RadStudio 10.3.3 Rio (Delphi C++ Builder)及TMS TAdvStringGrid控件安装方法
  16. 单片机八灯交替闪烁c语言代码,单片机闪烁灯汇编语言源代码大全(四款闪烁灯的汇编语言源代码)...
  17. 如何下载B站视频以及音频
  18. 数据挖掘4:自然语言处理(NLP)信息提取技术
  19. 数字图像处理 - Ch2 图像取样与量化
  20. js中自己实现bind方法及详解

热门文章

  1. npm run dev 报错echarts
  2. Linux云服务器安装Redis并设置远程连接设置开机自启
  3. PCL:python pcl解码RGB- point_cloud2.read_points rgb
  4. SLAM: Ubuntu14.04_Kylin安装ROS-Indigo
  5. 基于可靠消息方案的分布式事务:Lottor介绍
  6. 如何删除一个VDP服务器
  7. 第70天:jQuery基本选择器(一)
  8. 大数据在医疗保健中的真正愿景
  9. Android 内存泄漏总结文档
  10. 如何遍历维数和各维上限未定的多维数组