#import <UIKit/UIKit.h>

@interface ScrollUpDownView : UIView

//设置 要现实的文字
@property(nonatomic, strong)NSArray *array; // 开启定时器
- (void)onOpenTimer; // 关闭定时器
- (void)onOffTimer; @end
#import "ScrollUpDownView.h"

@interface ScrollUpDownView ()

@property(nonatomic, weak)UILabel *label1;

@property(nonatomic, weak)UILabel *label2;

@property(nonatomic, assign)NSInteger count;

@property(nonatomic, strong)NSTimer *timer;

@property(nonatomic, assign) CGFloat mainH;
@property(nonatomic, assign) CGFloat mainW;
@property(nonatomic, assign) CGFloat mainX;
@property(nonatomic, assign) CGFloat mainY; @end @implementation ScrollUpDownView - (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self initUIFrame:frame];
}
return self;
} - (void)setArray:(NSArray *)array
{
_array = array; } - (void)initUIFrame:(CGRect)rect
{
self.backgroundColor = [UIColor whiteColor];
_mainH = rect.size.height;
_mainW = rect.size.width;
_mainX = ;
_mainY = ; // bgView
UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(_mainX, _mainY, _mainW, _mainH)];
bgView.layer.masksToBounds = YES;
bgView.backgroundColor = [UIColor yellowColor];
bgView.layer.masksToBounds = YES;
bgView.layer.cornerRadius = CGRectGetHeight(bgView.frame) / ;
[self addSubview:bgView]; //
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(_mainX, _mainY, _mainW, _mainH)];
self.label1 = label1;
self.label1.textAlignment = NSTextAlignmentCenter;
self.label1.textColor = [UIColor whiteColor];
self.label1.font = [UIFont systemFontOfSize:];
label1.backgroundColor = [UIColor redColor];
[bgView addSubview:label1]; //
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(_mainX, _mainH, _mainW, _mainH)];
self.label2 = label2;
self.label2.textAlignment = NSTextAlignmentCenter;
self.label2.textColor = [UIColor whiteColor];
self.label2.font = [UIFont systemFontOfSize:];
label2.backgroundColor = [UIColor blueColor];
[bgView addSubview:label2]; self.count = ;
} // 开启定时器
- (void)onOpenTimer
{ if (self.array.count == ) return; NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: repeats: block:^(NSTimer * _Nonnull timer) { [UIView animateWithDuration: animations:^{ self.label1.frame = CGRectMake(_mainX, -_mainH, _mainW, _mainH);
self.label2.frame = CGRectMake(_mainX, _mainY, _mainW, _mainH); } completion:^(BOOL finished) {
self.label1.frame = CGRectMake(_mainX, _mainH, _mainW, _mainH);
if (self.count < self.array.count - ) {
self.count ++;
self.label1.text = self.array[self.count];
}else{
self.count = ;
//数据随机重组
[self OndataRandomReorganization];
self.label1.text = self.array[self.count];
} dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)( * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[UIView animateWithDuration: animations:^{
self.label2.frame = CGRectMake(_mainX, -_mainH, _mainW, _mainH);
self.label1.frame = CGRectMake(_mainX, _mainY, _mainW, _mainH);
} completion:^(BOOL finished) {
self.label2.frame = CGRectMake(_mainX, _mainH, _mainW, _mainH);
if (self.count < self.array.count - ) {
self.count ++;
self.label2.text = self.array[self.count];
}else{
self.count = ;
//数据随机重组
[self OndataRandomReorganization];
self.label2.text = self.array[self.count]; }
}];
});
}];
}]; self.timer = timer; // 开启定时器
[timer setFireDate:[NSDate distantPast]];
[[NSRunLoop currentRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];
}
// 关闭定时器
- (void)onOffTimer
{
[self.timer invalidate];
} //数据随机重组
- (void)OndataRandomReorganization
{
self.array = [self.array sortedArrayUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) {
int seed = arc4random_uniform();
if (seed) {
return [str1 compare:str2];
} else {
return [str2 compare:str1];
}
}];
} @end

引入

#import "ViewController.h"
#import "ScrollUpDownView.h"
@interface ViewController ()
@property(nonatomic, strong)ScrollUpDownView *dowmviewl; @property(nonatomic, strong)NSArray *array; @end @implementation ViewController - (NSArray *)array{ if (_array == nil) {
_array = @[@"我就想说:还有谁?",@"我可以一直杀",@"国服第一JS",@"我一贱,你就笑"];
}
return _array;
} - (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.dowmviewl onOpenTimer]; } -(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[self.dowmviewl onOffTimer]; } - (void)viewDidLoad {
[super viewDidLoad];
self.dowmviewl = [[ScrollUpDownView alloc]initWithFrame:CGRectMake(, , , )];
self.dowmviewl.backgroundColor = [UIColor yellowColor];
self.dowmviewl.array = self.array;
[self.view addSubview:self.dowmviewl];
} @end

ios - 上下滚动的新闻的更多相关文章

  1. (Android+IOS)正在做一个新闻App,做的差不多了,听听大家的建议 (图)

    (Android+IOS)正在做一个新闻App,做的差不多了,听听大家的建议! 新闻采集器做好了,前端展示APP界面感觉还不是很好,还需要改进改进,希望发布(Android和IOS版本)前听听大家的建 ...

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

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

  3. IOS在滚动的时候fixed消失

      前段时间,除了apple发布了新的硬件之外,同步还发布了新的操作系统,IOS11,当大家都将注意力聚焦在那个奇怪的刘海该如何适配的时候,笔者的项目在适配IOS11却出现了其他的问题. 众所周知,I ...

  4. IOS开发--仿制网易新闻

    学习来源:袁峥老师的<快速集成App中顶部标题滚动条> 此次博文写的是按需求分析写代码,思路条理性杠杠的,可以提高的编码实现速度哦. 效果:   根据这个网易新闻的界面,需求分析:     ...

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

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

  6. ios自动滚动图片功能源码

    源码AdScrollerView,一个已经封装好的UIScrollView的子类,可以自动滚动图片以及对应的描述语,类似淘宝app首页的广告滚动效果.滚动图片数量不限,并且显示pageControl. ...

  7. 【转】 iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)

    原文:http://blog.csdn.net/hmt20130412/article/details/34523235 本来只是打算介绍一下addChildViewController这个方法的,正 ...

  8. 【bug】—— ios scroll 滚动穿透

    BUG描述 在 ios 微信浏览器或原生浏览器中,主内容容器.content在文档流内,并且overflow-y: scroll.在其之上有一个 fixed 定位的弹出层.popUp,滚动.popUp ...

  9. iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)

    本文转载至 http://www.tuicool.com/articles/3ymMzub CSDN博客原文  http://blog.csdn.net/hmt20130412/article/det ...

随机推荐

  1. More is better——并查集求最大集合(王道)

    Description Mr Wang wants some boys to help him with a project. Because the project is rather comple ...

  2. 学习ajax总结

    之前公司的ajax学习分享,做一点总结,加深记忆 什么是ajax? 异步的的js和xml,用js异步形式操作xml,工作主要是数据交互 借阅用户操作时间,减少数据请求,可以无刷新请求数据 创建一个对象 ...

  3. Splunk 会议回想: 大数据的关键是机器学习

    作者 Jonathan Allen ,译者 张晓鹏 Splunk的用户大会已经接近尾声.三天时间的会议里,共进行了160多个主题研讨.涵盖了从安全.运营到商业智能.甚至包含物联网,会议中一遍又一遍出现 ...

  4. Android自己定义(三)实现圆盘的百分比设置

    近期一直在学习自己定义控件,昨天看到群里有人问怎样怎样实现圆盘样式的显示,学有所用,于是乎就有了这篇博客 先上图,一目了然 这里的显示颜色以及颜色块的大小你都能够自己设置 这里设置了三种颜色,相应三种 ...

  5. java集合框架小结

    总结例如以下: 1.假设要求线程安全的, 使用Vector.Hashtable 2.假设不要求线程安全,应该使用ArrayList.LinkedList.HashMap 3.假设要求有映射关系,键值对 ...

  6. Python——Socket 编程教程

    这是用来快速学习 Python Socket 套接字编程的指南和教程.Python 的 Socket 编程跟 C 语言很像. Python 官方关于 Socket 的函数请看 http://docs. ...

  7. jQuery 创建html

    jQuery 创建html

  8. 借鉴炉石传说的战棋游戏《DarkWar》

    <炉石传说>是现在很火的休闲对战游戏,本人也非常喜欢玩,玩的时候经常想能不能把炉石的这些元素融入到战棋类游戏中,于是思索良久,又恰逢游戏蛮牛开展第三届蛮牛杯游戏开发大赛,于是用Unity3 ...

  9. 【MyBatis学习02】走进MyBatis的世界

    mybatis是个持久层的框架,用来执行数据库操作的,无外乎增删改查,上一节对mybatis有了宏观上的了解后,这一篇博客主要通过一个小示例来入门mybatis,先看一下要写的示例需求: 根据用户id ...

  10. Windows外壳名字空间的浏览

    Windows95/98对Dos/Win3.x作了许多重大改进,在文件系统方面,它除了采用长文件名替代Dos中的8.3文件名以外,引入外壳名字空间(Shell Name Space)来代Dos文件系统 ...