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 ...
随机推荐
- 如何用路由器改成WiFi Pineapple系统镜像网络流量
本文主要介绍利用自己现有的设备,如何制作和使用WiFi Pineapple镜像网络流量,利用DWall模块分析用户数据,然后根据自己的需求,给DWall加入了日志记录功能.最后介绍了如何防范wifi ...
- Windows下搭建Solr环境
1.配置Java环境,可参考菜鸟教程:http://www.runoob.com/java/java-environment-setup.html (注意:在"系统变量"中设置3项 ...
- (草稿)spring @value 原理源码解读
一切要从这说起:http://www.cnblogs.com/guazi/p/6698654.html 我们直接开始debug: 这里会遍历所有的需要注入的InjectedElement 这里我们需要 ...
- [Spring boot] Configuring and Accessing a Data Source
We need our data persistence with configuring our datasouce: In application.properties: spring.h2.co ...
- 阿里云部署Java web项目初体验
林炳文Evankaka原创作品. 转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了怎样在阿里云上安装JDK.Tomcat以及其配置过程. 最后以一个实例来演 ...
- 恼人的The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved...错误,无奈用Struts的bean:write替代了JSTL的C:out
一个应用中有两个页面使用了JSTL的c:out输出,就类似这么简单三句 <c:if test="${!empty error}"> <h2>&l ...
- Rails generate的时候不生成assets和test
我们在执行rails g controller controller_name或者rails g model model_name的时候往往会生成相应的assets文件和test,怎么不让rails帮 ...
- annex-b格式
annex-b格式 总的来说H264的码流的打包方式有两种,一种为annex-b byte stream format的格式,这个是绝大部分编码器的默认输出格式,就是每个帧的开头的3~4个字节是H26 ...
- IOS Appstore价格表
- Python——标准库 Sys模块
---------------------------------------------------------------------------------------------------- ...