IOS 设置消息上下滚动,消息循环滚动视图
2015-10-26 00:00
423 查看
#import "NewsView.h" @interface ViewController (){ NSArray *rssArray; } @property (strong, nonatomic) NewsView *newsView; @end @implementation ViewController @synthesize newsView; static int countInt=0; static NSString *notice_index; - (void)viewDidLoad { [super viewDidLoad]; newsView=[[NewsView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 100.0f)]; [self.view addSubview:newsView]; rssArray=parkEntity.notice_rows; notice_index=[[rssArray objectAtIndex:0] objectForKey:@"id"]; [newsView.titleLabel setText:[[rssArray objectAtIndex:countInt] objectForKey:@"title"]]; [newsView.descriptionLabel setText:@"TESTDESCRIPTION"]; [newsView.newsButton addTarget:self action:@selector(topNewsInfoClicked:) forControlEvents:UIControlEventTouchUpInside]; [UIView animateWithDuration:0.7 delay:0 options:0 animations:^(){ newsView.alpha = 0.2; [newsView exchangeSubviewAtIndex:1 withSubviewAtIndex:0]; newsView.alpha = 1; } completion:^(BOOL finished){ //设置定时器 [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(displayNews) userInfo:nil repeats:YES]; }]; } -(void)displayNews{ countInt++; // long num = [rssArray count] >= 3 ? 3:[rssArray count]; if (countInt >= [rssArray count]) countInt=0; CATransition *animation = [CATransition animation]; animation.delegate = self; animation.duration = 0.5f ; animation.timingFunction = UIViewAnimationCurveEaseInOut; animation.fillMode = kCAFillModeForwards; animation.removedOnCompletion = YES; animation.type = @"cube"; notice_index=[[rssArray objectAtIndex:countInt] objectForKey:@"id"]; [newsView.layer addAnimation:animation forKey:@"animationID"]; [newsView setViewWithTitle:[[rssArray objectAtIndex:countInt] objectForKey:@"title"] description:@"test"]; } -(void)topNewsInfoClicked:(id)sender{ WebViewController *vc = [[WebViewController alloc] init]; vc.url = [NSString stringWithFormat:@"%@%@",PARKNOTICE_URL,notice_index]; vc.vcTitle = [[rssArray objectAtIndex:countInt] objectForKey:@"title"]; [self.navigationController pushViewController:vc animated:YES]; } @end
//NewsView.h // // NewsView.h // Created by Jack on 15-10-23. // Copyright (c) 2015年 Demo. All rights reserved. // #import <UIKit/UIKit.h> @interface NewsView : UIView @property (retain, nonatomic) UILabel *titleLabel; @property (retain, nonatomic) UILabel *descriptionLabel; @property (retain, nonatomic) UIButton *newsButton; -(void)setViewWithTitle:(NSString *)title description:(NSString *)description; @end
// NewsView.m // Created by Jack on 15-10-23. // Copyright (c) 2015年 Demo. All rights reserved. // #import "NewsView.h" @implementation NewsView @synthesize titleLabel; @synthesize descriptionLabel; @synthesize newsButton; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code //[self setBackgroundColor:[UIColor grayColor]]; titleLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 2, 211, 21)]; titleLabel.textColor=[UIColor grayColor]; titleLabel.backgroundColor=[UIColor clearColor]; titleLabel.font=[UIFont boldSystemFontOfSize:13.0]; // titleLabel.lineBreakMode = UILineBreakModeWordWrap; titleLabel.lineBreakMode = UILineBreakModeTailTruncation; titleLabel.numberOfLines = 1; [self addSubview:titleLabel]; descriptionLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 17, 260, 15)]; descriptionLabel.textColor=[UIColor blackColor]; descriptionLabel.backgroundColor=[UIColor clearColor]; descriptionLabel.font=[UIFont systemFontOfSize:11.0]; descriptionLabel.lineBreakMode = UILineBreakModeWordWrap; descriptionLabel.numberOfLines = 1; [self addSubview:descriptionLabel]; newsButton=[UIButton buttonWithType:UIButtonTypeCustom]; [newsButton setFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; [self addSubview:newsButton]; } return self; } -(void)dealloc{ // [titleLabel release]; // [descriptionLabel release]; // [super dealloc]; } -(void)setViewWithTitle:(NSString *)title description:(NSString *)description{ [titleLabel setText:title]; [descriptionLabel setText:description]; } @end
ps:参考
http://blog.csdn.net/totogo2010/article/details/8501812
相关文章推荐
- ionic+angularJS+iOS混合开发app的学习资料介绍和基本步骤(干货)
- iOS条码的生成
- iOS开发--OC对象模型你必须知道的几条规则
- KSImageNamed-Xcode插件在xcode 6.4/6.3或其余版本中不能使用解决方案
- Nagios配置文件详解
- iOS 将时间戳转换为可读字符串
- iOS开发必备--环境变量配置(Debug & Release)
- xcode7、iOS9 设置启动图片(Launch Image)
- 【小白装系统】——BIOS简介
- 动画缓冲
- 在Mac上安装CocoaPods以及在iOS工程中安装第三方类库
- 蓝懿ios 技术内容和心得 10.25
- 零基础ios开发(三 打僵尸)
- Xcode添加ios项目的空白模板
- iOS事件处理之思维导图
- iOS开发——RegressionBug和RegressionTest浅析
- iOS事件处理的思维导图
- iOS 计算某个时间距今天的天数
- iOS 将16数据转换成2进制字符串
- iOS 将二进制数据转换成十六进制字符串