ios - 上下滚动的新闻
#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 - 上下滚动的新闻的更多相关文章
- (Android+IOS)正在做一个新闻App,做的差不多了,听听大家的建议 (图)
(Android+IOS)正在做一个新闻App,做的差不多了,听听大家的建议! 新闻采集器做好了,前端展示APP界面感觉还不是很好,还需要改进改进,希望发布(Android和IOS版本)前听听大家的建 ...
- iOS界面-仿网易新闻左侧抽屉式交互 续(添加新闻内容页和评论页手势)
本文转载至 http://blog.csdn.net/totogo2010/article/details/8637430 1.介绍 有的博友看了上篇博文iOS界面-仿网易新闻左侧抽屉 ...
- IOS在滚动的时候fixed消失
前段时间,除了apple发布了新的硬件之外,同步还发布了新的操作系统,IOS11,当大家都将注意力聚焦在那个奇怪的刘海该如何适配的时候,笔者的项目在适配IOS11却出现了其他的问题. 众所周知,I ...
- IOS开发--仿制网易新闻
学习来源:袁峥老师的<快速集成App中顶部标题滚动条> 此次博文写的是按需求分析写代码,思路条理性杠杠的,可以提高的编码实现速度哦. 效果: 根据这个网易新闻的界面,需求分析: ...
- IOS之分析网易新闻存储数据(CoreData的使用,增删改查)
用过网易新闻客户端的朋友们都知道,获取新闻列表时有的时候他会请求网络有时候不会,查看某条新闻的时候再返回会标注已经查看的效果,接下来分析一下是如何实现的. 首先: 1.网易新闻用CoreData存储了 ...
- ios自动滚动图片功能源码
源码AdScrollerView,一个已经封装好的UIScrollView的子类,可以自动滚动图片以及对应的描述语,类似淘宝app首页的广告滚动效果.滚动图片数量不限,并且显示pageControl. ...
- 【转】 iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
原文:http://blog.csdn.net/hmt20130412/article/details/34523235 本来只是打算介绍一下addChildViewController这个方法的,正 ...
- 【bug】—— ios scroll 滚动穿透
BUG描述 在 ios 微信浏览器或原生浏览器中,主内容容器.content在文档流内,并且overflow-y: scroll.在其之上有一个 fixed 定位的弹出层.popUp,滚动.popUp ...
- iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
本文转载至 http://www.tuicool.com/articles/3ymMzub CSDN博客原文 http://blog.csdn.net/hmt20130412/article/det ...
随机推荐
- LinkedIn是如何优化Kafka的
作者 张卫滨 发布于 2015年9月21日 转载 在LinkedIn的数据基础设施中,Kafka是核心支柱之一.来自LinkedIn的工程师曾经就Kaf ...
- 安装notepad++ in ubuntu16.04
一.安装notepad++ Ubuntu下的安装方法: sudo add-apt-repository ppa:notepadqq-team/notepadqq sudo apt-get update ...
- vagrant 知识库
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明 http://wushaobo.info/?p=83 Vagrant让虚拟化技术走近寻常家.脚踏实地地说,网络上类似“两分钟入门”的文 ...
- Solution of NumberOfDiscIntersections by Codility
question:https://codility.com/programmers/lessons/4 this question is seem like line intersections qu ...
- 作为Java程序员应该掌握的10项技能
本文详细罗列了作为Java程序员应该掌握的10项技能.分享给大家供大家参考.具体如下: 1.语法:必须比较熟悉,在写代码的时候IDE的编辑器对某一行报错应该能够根据报错信息知道是什么样的语法错误并且知 ...
- Node.js abaike图片批量下载Node.js爬虫1.00版
这个与前作的差别在于地址的不规律性,需要找到下一页的地址再爬过去找. //====================================================== // abaik ...
- 用C++实现文件压缩(1.5)
今天主要做的就是,将完成huffman编码的数据以二进制的形式写入文件中.这是个挺苦逼的活. 不过好在我以前玩过一段时间的单片机,所有能够较好的实现位运算,一位一位的将数据存放到缓冲区中,然后统一写入 ...
- Memcachedclientutils类
0.个人标签 我的CSDN博客地址: http://blog.csdn.net/caicongyang 1.依赖的jar包 commons-pool-1.5.6.jar slf4j-api-1.6.1 ...
- driver: Linux设备模型之input子系统具体解释
本节从总体上解说了输入子系统的框架结构.有助于读者从总体上认识linux的输入子系统.在陷入代码分析的过程中,通过本节的知识可以找准方向,明确原理. 本节重点: 输入子系统的框架结构 各层相应内核中的 ...
- [linux]w命令和uptime命令查看系统负载
在Linux系统中查询系统CPU和内存的负载(使用率)时,我们通常习惯于使用top.atop或者ps,这篇文章将要给大家介绍如何使用w命令和uptime命令来查看系统的负载情况,对于uptime命令, ...