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 ...
随机推荐
- cpu压力测试
一.cpu压力测试 1.安装stress软件 sudo apt-get install stress #加压 nohup stress --cpu 8 & #查看cpu负载 top
- CSS3 animation动画
CSS3 animation动画 1.@keyframes 定义关键帧动画2.animation-name 动画名称3.animation-duration 动画时间4.animation-timin ...
- 实现一个JDK代理demo
JDK代理,非常简单地实现了动态代理(首先是实现对应的InvocationHandler:然后,以接口来为被调用目标构建代理对象,代理对象简介运行调用目标,并提供额外逻辑插入) 缺点:它是只能以接口为 ...
- 集合—ArrayList
ArrayList也叫作数组列表 public static void main(String[] args) { List list1 = new ArrayList<String>() ...
- shell中单引号、双引号、反引号的区别
'单引号' 忽略所有特殊字符 "双引号" 忽略大部分特殊字符,除了$ ` `反引号` 输出执行结果
- Node.js meitulu图片批量下载爬虫 1.05版(Final最终版)
//====================================================== // https://www.meitulu.com图片批量下载Node.js爬虫1. ...
- 【CI】系列三.宿主机KVM配置及vdi与vmdk格式转换等
前提:宿主机需要支持虚拟化,如果未打开,则需要重启机器,在bois中打开该项: Ubuntu 及 KVM 相关主要参考官方 https://wiki.ubuntu.com/kvm 另外也可参考该页面: ...
- iOS怎样找到自己的沙盒
iOS怎样找到自己的沙盒 在ios开发我们会用到沙盒,因为自己对沙盒理解的不够,所以找不到沙盒文件在哪里,当然要知道路径了 比如我的路径 NSString* cachepath = [NSHomeDi ...
- 为InfiniBand而哭泣
自古就不乏还没有開始就结束的那种精彩.我称之为殉道者.InfiniBand就是当中之中的一个.尽管它有陨落之势,我依旧要为它鼓掌. 假设说以太网旨在将主机联系在一起,那么InfiniBand的初衷就是 ...
- HTTP——请求和响应格式
HTTP请求格式:<request-line><headers><blank line>[<request-body>]说明:第一行必须是一个请求行(r ...