iOS界面-仿网易新闻左侧抽屉式交互 续(添加新闻内容页和评论页手势)
1、介绍
有的博友看了上篇博文iOS界面-仿网易新闻左侧抽屉式交互 ,在微博里问,网易新闻里的内容和评论的拖拽如何实现,
上面的UINavigation如何嵌进去。可能不少人有这样的需求,现在花了些时间把这两个效果做一下,
和大家分享交流。思路和上篇基本差不多,但是没有用到UINavigation,其实在我看来上面的返回、
评论按钮都是可以通过addsubview添加的。内容页和评论页的手势交互 实现的效果如下:


2、跳转添加


3、部分代码
--
- #import <UIKit/UIKit.h>
- @class CommentView;
- @interface DetailView : UIView
- {
- CommentView *commentView;
- BOOL isPanComment;
- }
- - (id)initWithView:(UIView*)contentView parentView:(UIView*) parentView;
- @property (nonatomic, strong) UIView *parentView; //抽屉视图的父视图
- @property (nonatomic, strong) UIView *contentView; //抽屉显示内容的视图
- @end
- //
- // DetailView.m
- // NeteaseNews
- //
- // Created by rongfzh on 13-3-5.
- // Copyright (c) 2013年 rongfzh. All rights reserved.
- //
- #import "DetailView.h"
- #import "CommentView.h"
- #import <QuartzCore/QuartzCore.h>
- @implementation DetailView
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- // Initialization code
- }
- return self;
- }
- - (id)initWithView:(UIView *)contentView parentView:(UIView *)parentView{
- self = [super initWithFrame:CGRectMake(0,0,contentView.frame.size.width, contentView.frame.size.height)];
- if (self) {
- [self addSubview:contentView];
- UIPanGestureRecognizer *panGestureRecognier = [[UIPanGestureRecognizer alloc]
- initWithTarget:self
- action:@selector(HandlePan:)];
- [self addGestureRecognizer:panGestureRecognier];
- UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- backBtn.frame = CGRectMake(0, 0, 80, 50);
- [backBtn addTarget:self
- action:@selector(back:)
- forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:backBtn];
- UIImageView *imageCommentView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"comment.png"]];
- imageCommentView.frame = CGRectMake(0, 0,
- self.frame.size.width,
- self.frame.size.height);
- commentView = [[CommentView alloc] initWithView:imageCommentView parentView:self];
- commentView.center = CGPointMake(480, 230);
- [[commentView layer] setShadowOffset:CGSizeMake(10, 10)];
- [[commentView layer] setShadowRadius:20];
- [[commentView layer] setShadowOpacity:1];
- [[commentView layer] setShadowColor:[UIColor blackColor].CGColor];
- [self addSubview:commentView];
- isPanComment = NO;
- }
- self.parentView = parentView;
- return self;
- }
- - (void)HandlePan:(UIPanGestureRecognizer*)panGestureRecognizer{
- CGPoint translation = [panGestureRecognizer translationInView:self.parentView];
- float x = self.center.x + translation.x;
- if (x < 160) {
- x = 160;
- }
- if(translation.x > 0){
- if (!isPanComment) {
- self.center = CGPointMake(x, 230);
- }
- }
- if (translation.x < 0 && self.center.x > 160) {
- if (!isPanComment) {
- self.center = CGPointMake(x, 230);
- }
- }else if(translation.x < 0){
- isPanComment = YES;
- commentView.center = CGPointMake(commentView.center.x + translation.x, 230);
- }
- if (commentView.center.x < 480 && translation.x > 0) {
- isPanComment = YES;
- commentView.center = CGPointMake(commentView.center.x + translation.x, 230);
- }
- if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
- if (commentView.center.x < 400) {
- [UIView animateWithDuration:0.4
- delay:0.1
- options:UIViewAnimationCurveEaseInOut
- animations:^(void){
- commentView.center = CGPointMake(160, 230);
- }completion:^(BOOL finish){
- isPanComment = NO;
- }];
- }else{
- [UIView animateWithDuration:0.4
- delay:0.1
- options:UIViewAnimationCurveEaseInOut
- animations:^(void){
- commentView.center = CGPointMake(480, 230);
- }completion:^(BOOL finish){
- isPanComment = NO;
- }];
- }
- if (self.center.x > 190) {
- [UIView animateWithDuration:0.4
- delay:0.1
- options:UIViewAnimationCurveEaseInOut
- animations:^(void){
- self.center = CGPointMake(480, 230);
- }completion:^(BOOL finish){
- [self.parentView exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
- }];
- }else{
- [UIView animateWithDuration:0.4
- delay:0.1
- options:UIViewAnimationCurveEaseInOut
- animations:^(void){
- self.center = CGPointMake(160, 230);
- }completion:^(BOOL finish){
- }];
- }
- }
- [panGestureRecognizer setTranslation:CGPointZero inView:self.parentView];
- }
- - (void) back:(id)sender{
- [UIView animateWithDuration:0.4
- delay:0.1
- options:UIViewAnimationCurveEaseInOut
- animations:^(void){
- self.center = CGPointMake(480, 230);
- }completion:^(BOOL finish){
- [self.parentView exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
- }];
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect
- {
- // Drawing code
- }
- */
- @end
3、评论页的view和内容页的代码差不多
代码还有很多值得优化的地方,现在只是展示实现了功能,手势判断部分代码比较乱,只要掌握了手势的原来,代码可以自己根据需求来修改
代码:
Github:https://github.com/schelling/NeteaseNews
iOS界面-仿网易新闻左侧抽屉式交互 续(添加新闻内容页和评论页手势)的更多相关文章
- Android应用经典主界面框架之二:仿网易新闻client、CSDN client (Fragment ViewPager)
另外一种主界面风格则是以网易新闻.凤凰新闻以及新推出的新浪博客(阅读版)为代表.使用ViewPager+Fragment,即ViewPager里适配器里放的不是一般的View.而是Fragment.所 ...
- iOS仿网易新闻栏目拖动重排添加删除效果
仿网易新闻栏目选择页面的基本效果,今天抽了点时间教大家如何实现UICollectionView拖动的效果! 其实实现起来并不复杂,这里只是基本的功能,没有实现细节上的修改,连UI都是丑丑的样子,随手画 ...
- Android 开源框架ActionBarSherlock 和 ViewPager 仿网易新闻客户端
转载请注明出处:http://blog.csdn.net/xiaanming/article/details/9971721 大家都知道Android的ActionBar是在3.0以上才有的,那么在3 ...
- 类似掌盟的Tab页 Android 开源框架ViewPageIndicator 和 ViewPager 仿网易新闻客户端Tab标签 (转)
原博客地址 :http://blog.csdn.net/xiaanming/article/details/10766053 本文转载,记录学习用,如有需要,请到原作者网站查看(上面这个网址) 之前 ...
- Android Studio精彩案例(一)《ActionBar和 ViewPager版仿网易新闻客户端》
转载本专栏文章,请注明出处,尊重原创 .文章博客地址:道龙的博客 为了能更好的分享高质量的文章,所以开设了此专栏.文章代码都以Android Studio亲测运行,读者朋友可在后面直接下载源码.该专栏 ...
- 动态权限<二>之淘宝、京东、网易新闻 权限申请交互设计对比分析
移动智能设备的快速普及,给生活带来巨大的精彩,但是智能设备上用户的信息数据很多,隐私数据也非常多,各种各样的app可能通过各种方式在悄悄的收集用户数据,而用户的隐私就变得耐人寻味了.比如之前的可以无限 ...
- Android 开源框架ViewPageIndicator 和 ViewPager 仿网易新闻clientTab标签
之前用JakeWharton的开源框架ActionBarSherlock和ViewPager实现了对网易新闻clientTab标签的功能,ActionBarSherlock是在3.0下面的机器支持Ac ...
- Android 开源框架ViewPageIndicator 和 ViewPager 仿网易新闻客户端Tab标签
转载请注明出处:http://blog.csdn.net/xiaanming/article/details/10766053 之前用JakeWharton的开源框架ActionBarSherlock ...
- 仿网易新闻 ViewPager 实现图片自动轮播
新闻 App 首页最上方一般会循环播放热点图片,如下图所示. 本文主要介绍了利用 ViewPager 实现轮播图片,图片下方加上小圆点指示器标记当前位置,并利用 Timer+Handler 实现了自动 ...
随机推荐
- asp.net内置对象 Response对象使用介绍
Response对象是HttpRespone类的一个实例.该类主要是封装来自ASP.NET操作的HTTP相应信息.Response对象将数据作为请求的结果从服务器发送到客户浏览器中,并提供有关响应的消 ...
- 转载自——Json.Net如何在序列化之前修改属性值
今天写一个Json.net比较偏门的用法,也许你很久都用不到,也许你明天就能派上用场. 我们都知道 Json.net 序列话的用法 Test test = new Test() { A = " ...
- js-Flexbox盒子布局
这个年轻的时候,我在项目中其实很少用到: 现在老了,发现了他的好处,我就开始慢慢用到了: 但是其实我对他还是不熟悉的,很陌生,在此做个笔记,加油
- BZOJ1088(SCOI2005)
枚举第一行第一个格子的状态(有雷或者无雷,0或1),然后根据第一个格子推出后面所有格子的状态.推出之后判断解是否可行即可. #include <bits/stdc++.h> using n ...
- ABS已死: Archlinux 放弃支持 ABS
今天访问archlinux官网,突然看到官方放弃支持ABS的新闻,声明如下: 由于 Arch Build System 的相关服务器端脚本的维护开销日益增高,我们决定放弃 abs及其相关的通过 rsy ...
- 使用log4net无法将日志记录插入mysql数据库解决办法
写在前面 今天没事研究了下,将日志文件写入mysql数据库,因为新公司用的数据库也是mysql,项目中需要将日志信息写入数据库,没办法,就研究了下.在使用过程中遇到一个很蛋疼的问题.最后解决了,郁闷了 ...
- 人生中的那口井 z
有两个和尚住在隔壁,每天都会在同一时间下山去溪边挑水,不知不觉己经过了五年. 突然有一天,左边这座山的和尚没有下山挑水,过了一个星期,还是没有下山挑水. 直到过了一个月,右边那座山的和尚很担心就去探望 ...
- 如何判断自己外网IP是否为真实公网IP,以及解决方案
如何判断本地(路由器)分配的IP是否公网IP? 公网IP:全球唯一IP地址.(公网IP又分为静态公网IP和动态公网IP,如何分辨的话,进入路由器查看连接方式pppoe连接都是动态公网IP.) ...
- 灰度发布+A/B测试
一起需要提的还有灰度发布. 在方法论上都属于试错法. A/B测试就是上两个方案,部署后看效果.根据效果和一些结果参数决定采用哪个方案.灰度发布是切一部分业务使用新方案,看效果如何,是否有bug,会遇到 ...
- ThinkPHP3.1 模板布局
ThinkPHP的模板引擎内置了布局模板功能支持,可以方便的实现模板布局以及布局嵌套功能.有三种布局模板的支持方式: 第一种方式:全局配置方式 这种方式仅需在项目配置文件中添加相关的布局模板配置,就可 ...