//

//  ViewController.m

//  wyy

//

//  Copyright © 2016年 zm. All rights reserved.

//

#import "ViewController.h"

#import "ZMViewController.h"

#import "ZMLabel.h"

@interface ViewController ()<UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *titleScrllView;

@property (weak, nonatomic) IBOutlet UIScrollView *contentScrollview;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

self.automaticallyAdjustsScrollViewInsets = NO;

self.title = @"网易新闻";

[self setUpChildVC];

[self setUpTitle];

//默认选中第一页  调用此方法

[self scrollViewDidEndScrollingAnimation:self.contentScrollview];

}

//创建头部标题视图

- (void)setUpTitle{

CGFloat w = 100;

CGFloat y = 0;

CGFloat h = self.titleScrllView.frame.size.height;

for (int i = 0; i < 7; i++) {

ZMLabel *lable = [[ZMLabel alloc]initWithFrame:CGRectMake(i*w, y, w, h)];

lable.text = [self.childViewControllers[i] title];

//给lable添加手势

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];

[lable addGestureRecognizer:tap];

[self.titleScrllView addSubview:lable];

}

self.titleScrllView.contentSize = CGSizeMake(7*w, 0);

self.contentScrollview.contentSize = CGSizeMake(7*[UIScreen mainScreen].bounds.size.width, 0);

}

- (void)tap:(UITapGestureRecognizer *)tap{

NSInteger index = [self.titleScrllView.subviews indexOfObject:tap.view];

//通过手势设置内容滚动视图的偏移量

[self.contentScrollview setContentOffset:CGPointMake([UIScreen mainScreen].bounds.size.width * index, 0) animated:YES];

}

//当动画结束时调用此方法

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{

CGFloat w = scrollView.frame.size.width;

CGFloat h = scrollView.frame.size.height;

CGFloat offsetX = scrollView.contentOffset.x;

NSInteger index = offsetX/w;

ZMLabel *lab = self.titleScrllView.subviews[index];

CGFloat offsetx = lab.center.x - scrollView.frame.size.width*0.5;

//判断offsetx最大最小值两种情况

if (offsetx < 0) {

offsetx = 0;

}

if (offsetx > (self.titleScrllView.contentSize.width - scrollView.frame.size.width)) {

offsetx = self.titleScrllView.contentSize.width - scrollView.frame.size.width;

}

self.titleScrllView.contentOffset = CGPointMake(offsetx, 0);

UIViewController *zm = self.childViewControllers[index];

if ([zm isViewLoaded]) return;

zm.view.frame = CGRectMake(index *w, 0, w, h);

[self.contentScrollview addSubview:zm.view];

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

[self scrollViewDidEndScrollingAnimation:scrollView];

}

- (void)setUpChildVC{

ZMViewController *zm = [[ZMViewController alloc]init];

zm.title = @"新闻";

[self addChildViewController:zm];

ZMViewController *zm1 = [[ZMViewController alloc]init];

zm1.title = @"军事";

[self addChildViewController:zm1];

ZMViewController *zm2 = [[ZMViewController alloc]init];

zm2.title = @"政治";

[self addChildViewController:zm2];

ZMViewController *zm3 = [[ZMViewController alloc]init];

zm3.title = @"娱乐";

[self addChildViewController:zm3];

ZMViewController *zm4 = [[ZMViewController alloc]init];

zm4.title = @"社会";

[self addChildViewController:zm4];

ZMViewController *zm5 = [[ZMViewController alloc]init];

zm5.title = @"科技";

[self addChildViewController:zm5];

ZMViewController *zm6 = [[ZMViewController alloc]init];

zm6.title = @"啦啦";

[self addChildViewController:zm6];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

CGFloat scale = scrollView.contentOffset.x/scrollView.frame.size.width;

NSInteger leftIndex = scale;

NSInteger rightIndex = scale+1;

if (scale < 0 || scale > self.titleScrllView.subviews.count-1) return;

CGFloat rightScale = scale - leftIndex;

CGFloat leftScale = 1-rightScale;

ZMLabel *leftLabel = self.titleScrllView.subviews[leftIndex];

ZMLabel *rightLabel = (rightIndex == self.titleScrllView.subviews.count)?nil:(self.titleScrllView.subviews[rightIndex]);

leftLabel.scale = leftScale;

rightLabel.scale = rightScale;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

// 自定义一个lable 继承于uilable

//

//  ZMLabel.m

//  wyy

//

//  Copyright © 2016年 zm. All rights reserved.

//

#import "ZMLabel.h"

@implementation ZMLabel

- (instancetype)initWithFrame:(CGRect)frame{

if (self =[super initWithFrame:frame]) {

self.textAlignment = NSTextAlignmentCenter;

self.userInteractionEnabled = YES;

self.textColor = [UIColor blackColor];

self.font = [UIFont systemFontOfSize:15];

}

return self;

}

- (void)setScale:(CGFloat)scale{

CGFloat transform = scale*0.3+1;

self.transform = CGAffineTransformMakeScale(transform, transform);

self.textColor = [UIColor colorWithRed:transform-1 green:0 blue:0 alpha:1];

}

@end

//创建控制器   这里可以为了简易就只创建一个控制器

//

//  ZMViewController.m

//  wyy

//

//  Copyright © 2016年 zm. All rights reserved.

//

#import "ZMViewController.h"

@interface ZMViewController ()

@end

@implementation ZMViewController

- (void)viewDidLoad {

[super viewDidLoad];

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

#warning Incomplete implementation, return the number of sections

return 1;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

#warning Incomplete implementation, return the number of rows

return 50;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"forIndexPath:indexPath];

cell.textLabel.text = [NSString stringWithFormat:@"%@-%ld",self.title,indexPath.row];

return cell;

}

@end

网易新闻首页iOS的更多相关文章

  1. 转:addChildViewController实现网易新闻首页切换

    本来只是打算介绍一下addChildViewController这个方法的,正好今天朋友去换工作面试问到网易新闻标签栏效果的实现,就结合它,用个小Demo实例介绍一下:(具体解释都写在了Demo里面的 ...

  2. IOS 类似于网易新闻首页新闻轮播的组件

    一.需求分析 1.可横向循环滚动新闻图片 2.滚动到对应图片时显示新闻标题 3.每张新闻图片可点击 4.有pageControl提示 5.具有控件的扩展能力 二.设计实现 1.显示图片使用SDWebI ...

  3. android 仿网易新闻首页框架

       实现思路很简单左侧栏目是一个一个的 Fragment 的,点击时动态替换各个 Fragment 到当前 Activity 中. 关键代码: public void loadFragment(Ma ...

  4. iOS 网易新闻用到的框架

    网易新闻iOS版在开发过程中曾经使用过的第三方开源类库.组件 1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务 ...

  5. 网易新闻iOS版使用的18个开源组件

    转载来自:http://www.jianshu.com/p/8952944f7566  原文最后编辑时间:2015.05.19 网易新闻iOS版在开发过程中曾经使用过的第三方开源类库.组件 1.AFN ...

  6. IOS之分析网易新闻存储数据(CoreData的使用,增删改查)

    用过网易新闻客户端的朋友们都知道,获取新闻列表时有的时候他会请求网络有时候不会,查看某条新闻的时候再返回会标注已经查看的效果,接下来分析一下是如何实现的. 首先: 1.网易新闻用CoreData存储了 ...

  7. ActionBar+DrawerLayout实现网易新闻客户端首页

    一.概述 随着android版本的不断的更新,google推出了越来越多的高级组件,采用这些官方组件我们可以方便的实现一些以前需要通过复杂编码或者使用第三方组件才能实现的效果,比如slidingmen ...

  8. iOS界面-仿网易新闻左侧抽屉式交互 续(添加新闻内容页和评论页手势)

     本文转载至  http://blog.csdn.net/totogo2010/article/details/8637430       1.介绍 有的博友看了上篇博文iOS界面-仿网易新闻左侧抽屉 ...

  9. iOS仿网易新闻栏目拖动重排添加删除效果

    仿网易新闻栏目选择页面的基本效果,今天抽了点时间教大家如何实现UICollectionView拖动的效果! 其实实现起来并不复杂,这里只是基本的功能,没有实现细节上的修改,连UI都是丑丑的样子,随手画 ...

随机推荐

  1. GDB调试之core文件(如何定位到Segment fault)

    core dump又叫核心转储,当程序运行过程中发生异常,程序异常退出时,由操作系统把程序当前的内存状况存储在一个core文件中,叫core dump.(内部实现是:linux系统中内存越界会收到SI ...

  2. HTTP学习笔记——URL与资源

    什么是URL? 所有的东西都有一个标准化的东西,公交有线路号,飞机有航班号,个人有身份证号,你坐出租车,告诉司机师傅我要到石牌华师,他就能明白你的意思了.URL就是因特网资源的标准化名称.URL指向一 ...

  3. SSIS: 使用Lookup 和 Cache transformation 进行数据匹配简单介绍

    本文将讲解Cache transformation的使用方式,并且用Lookup transformation进行匹配. 背景 如下图,我们的产品目标表中有些有尺寸信息有些没有.我们需要用Cache组 ...

  4. objective-C学习笔记(四)函数成员:方法(函数)

    函数分为:  全局函数(C语言函数) 成员函数(OBJC方法):实例方法 “-” 和类方法“+”的区别 //这里要区别静态变量(类变量).全局函数.常量的区别 OBJC里面,所有方法默认为公有方法.没 ...

  5. JavaSE复习日记 : 条件判断语句

    /* 条件控制语句:if(){}else{} 语法: 第一种结构:有不执行的情况 if(boolean表达式){ //第一位真,就执行里面的语句,为假就不执行 java语句; } 第二种结构: if( ...

  6. c++ primer plus 习题答案(2)

    p221.8 #include<iostream> #include<cstdlib> #include<cstring> using namespace std; ...

  7. javascript函数querySelector

    querySelector用于获得dom节点,可以接受三种类型的参数:id(#),class(.),标签.很像jquery的选择器.不过只能返回一个子孙元素,但是jquery选择器的话,可以返回一组元 ...

  8. object-c 协议(Protocols)和代理(Delegation)的学习

    代理是Object-C中的一个重要机制,他可以将面向对象编程的封装特性进一步加强,不是自己负责的事情坚决不做,而是转而让对应的事情负责人(代理)去做.相反如果是自己需要负责的事情(作为别人的代理),会 ...

  9. web压缩gzip响应

    String data = "ggrgrgw4gergergregerge"; byte b[] = data.getBytes(); String gzipValue = req ...

  10. 有意思的C宏

    在Linux内核.嵌入式代码等传统的C代码里,会有一些难以识别的宏定义.我记得在eCos, UBoot, FFmpeg有一些比较BT的宏定义,很难读懂.对于C++程序员来说,最好将这种难读的宏定义转成 ...