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 ...
随机推荐
- ubuntu16.04给普通用戸提成root权限,会出现造成重启系统,没有登录用户
一.导致问题的原因 直接修改配置文件提权,会造成重启系统后没有原来的登录用户 vim /etc/passwd nulige:x:0:0:nulige,,,:/home/gree:/bin/bash 解 ...
- 倍福TwinCAT(贝福Beckhoff)应用教程11.1 TwinCAT应用小程序1 贝福IO模块介绍
EL1002,EL1004,EL1008都是数字输入模块(2个点,4个点,8个点),输入高的范围是15V到30V,低的范围是-3V到5V EL2002,EL2004,EL2008都是数 ...
- Django——如何处理请求(URL配置和视图)
URLconfig—— 为了绑定视图函数和URL,我们使用URLconf. URLconf 就像是 Django 所支撑网站的目录. 它的本质是 URL 模式以及要为该 URL 模式调用的视图函数之间 ...
- 在OpenErp的配置文件中为数据库密码加密
openerp连接数据库的用户名和密码可以命令行给出, 也可以设置在配置文件中, 如下例所示: db_user = openerp db_password = laoliu 因为它使用了明文的密码 ...
- 【English】口头禅
1. Absolutely! 毫无疑问! 2. Adorable! 可爱极了! 3. Amazing! 太神奇了! 4. Anytime! 随时吩咐! 5. Almost! 差不多了! 6. Awfu ...
- Loadrunner Analysis之Web Page Diagnostics
Loadrunner Analysis之Web Page Diagnostics 分类: LoadRunner 性能测试 2012-12-31 18:47 1932人阅读 评论(2) 收藏 举报 di ...
- CefSharp.WinForms
CefSharp.WinForms 一. 前言 银医通项目,现在另外一家医院需要上系统,所以项目需要重新搭建,由于这家医院的His系统和另外一家医院的His系统不同,界面风格也不一致,所以重新搭建, ...
- PHP,mysql,Linux,CI框架学习总结
PHP,mysql,CI框架学习总结 PHP标记 1.Xml风格<?php ?> 2.简短风格 <? ?> 需在php.ini中开启short_open_tag 3.asp风格 ...
- DNS的概念,用途,DNS查询的实现算法
1.DNS的概念,用途 DNS是由解析器以及域名服务器组成的. 域名服务器是指保存有该网络中所有主机的域名和对应IP地址,并具有将域名转换为IP地址功能的服务器. DNS ...
- 对象关系映射 EmitMapper 及Tuple的使用
public TDestination Map<TSource, TDestination>(TSource tSource) { if (tSource == null) return ...