Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
1. fix 首次进入偶尔归位重新开始(JhtHorizontalMarquee)
2. Adjust inside code
  • Loading branch information
jinht committed May 25, 2018
1 parent b675aaf commit baf2725
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 103 deletions.
24 changes: 6 additions & 18 deletions JhtMarquee.framework/Headers/JhtHorizontalMarquee.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,14 @@
// Copyright © 2016年 JhtMarquee. All rights reserved.
//

/************支持attributedText************/

#import <UIKit/UIKit.h>
#import "JhtHorizontalMarquee_Define.h"

/** 跑马灯状态_枚举 */
typedef NS_ENUM(NSUInteger, MarqueeState_H) {
// 开启
MarqueeStart_H,
// 关闭
MarqueeShutDown_H,
// 暂停
MarqueePause_H,
// 取消暂停(继续)
MarqueeContinue_H,
};

/** 水平滚动的跑马灯 */
/** 横向 跑马灯 */
@interface JhtHorizontalMarquee : UILabel

#pragma mark - property
/** 获取_是否处于_暂停状态(只读) */
/** 获取_是否处于_暂停状态 */
@property (nonatomic, assign, readonly) BOOL isPaused;


Expand All @@ -41,8 +29,8 @@ typedef NS_ENUM(NSUInteger, MarqueeState_H) {

#pragma mark 设置跑马灯状态
/** 设置跑马灯状态
* marqueeState:跑马灯状态(枚举
* 注:开启跑马灯放在viewDidAppear中,关闭跑马灯放在viewWillDisappear中
* marqueeState:跑马灯状态(MarqueeState_H
* 注:开启跑马灯放在viewDidAppear中,关闭跑马灯放在viewWillDisappear中
*/
- (void)marqueeOfSettingWithState:(MarqueeState_H)marqueeState;

Expand Down
26 changes: 26 additions & 0 deletions JhtMarquee.framework/Headers/JhtHorizontalMarquee_Define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// JhtHorizontalMarquee_Define.h
// JhtMarquee
//
// Created by Jht on 2018/5/25.
// Copyright © 2018年 JhtMarquee. All rights reserved.
//

#ifndef JhtHorizontalMarquee_Define_h
#define JhtHorizontalMarquee_Define_h


/** 跑马灯状态_枚举 */
typedef NS_ENUM(NSUInteger, MarqueeState_H) {
// 开启
MarqueeStart_H,
// 关闭
MarqueeShutDown_H,
// 暂停
MarqueePause_H,
// 取消暂停(继续)
MarqueeContinue_H,
};


#endif /* JhtHorizontalMarquee_Define_h */
42 changes: 13 additions & 29 deletions JhtMarquee.framework/Headers/JhtVerticalMarquee.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,43 @@
//

#import <UIKit/UIKit.h>
#import "JhtVerticalMarquee_Define.h"

/** 跑马灯状态_枚举 */
typedef NS_ENUM(NSUInteger, MarqueeState_V) {
// 开启
MarqueeStart_V,
// 关闭
MarqueeShutDown_V,
// 暂停
MarqueePause_V,
// 取消暂停(继续)
MarqueeContinue_V
};

/** 上下滚动的跑马灯 */
/** 纵向 跑马灯 */
@interface JhtVerticalMarquee : UIView

#pragma mark - Property
#pragma mark required
/** 滚动文字的 数据源数组(支持attributedText与text混合) */
/** 跑马灯文字 数据源数组(支持attributedText与text混合) */
@property (nonatomic, strong) NSArray *sourceArray;


#pragma mark optional
/** 当前显示展示的文字 在数据源数组中的索引_只读 */
/** 当前展示内容 索引 */
@property (nonatomic, assign, readonly) NSInteger currentIndex;

/** 是否为逆时针滚动(default:NO)
* 顺时针:底部 ===> 顶部
* 逆时针:顶部 ===> 底部
*/
@property (nonatomic, assign) BOOL isCounterclockwise;

/** 单次滚动时间
/** 单次滚动 时间
* default:0.5f
*/
@property (nonatomic, assign) CGFloat scrollDuration;
/** 滚动延迟
* default:2.5f
/** 滚动延迟 时间
* default:3.0f
*/
@property (nonatomic, assign) CGFloat scrollDelay;

/** 滚动文字的颜色
/** 文字 颜色
* default:[UIColor blackColor]
*/
@property (nonatomic, strong) UIColor *verticalTextColor;
/** 滚动文字的字体
/** 文字 字体
* default:[UIFont systemFontOfSize:14]
*/
@property (nonatomic, strong) UIFont *verticalTextFont;
/** 显示文字的对齐方式
/** 文字 对齐方式
* default:NSTextAlignmentLeft
*/
@property (nonatomic, assign) NSTextAlignment verticalTextAlignment;
/** 显示文字的行数
/** 文字 行数
* default:2(注意一下self.frame的设置)
*/
@property (nonatomic, assign) NSInteger verticalNumberOfLines;
Expand All @@ -75,7 +59,7 @@ typedef NS_ENUM(NSUInteger, MarqueeState_V) {
*/
- (void)marqueeOfSettingWithState:(MarqueeState_V)marqueeState;

/** 每次滚动回调的Block */
/** 滚动 回调 */
typedef void(^verticalMarqueeBlock)(JhtVerticalMarquee *view, NSInteger currentIndex);
- (void)scrollWithCallbackBlock:(verticalMarqueeBlock)block;

Expand Down
26 changes: 26 additions & 0 deletions JhtMarquee.framework/Headers/JhtVerticalMarquee_Define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// JhtVerticalMarquee_Define.h
// JhtMarquee
//
// Created by Jht on 2018/5/25.
// Copyright © 2018年 JhtMarquee. All rights reserved.
//

#ifndef JhtVerticalMarquee_Define_h
#define JhtVerticalMarquee_Define_h


/** 跑马灯状态_枚举 */
typedef NS_ENUM(NSUInteger, MarqueeState_V) {
// 开启
MarqueeStart_V,
// 关闭
MarqueeShutDown_V,
// 暂停
MarqueePause_V,
// 取消暂停(继续)
MarqueeContinue_V
};


#endif /* JhtVerticalMarquee_Define_h */
Binary file modified JhtMarquee.framework/Info.plist
Binary file not shown.
Binary file modified JhtMarquee.framework/JhtMarquee
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
135 changes: 79 additions & 56 deletions JhtMarquee/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#define FrameW [UIScreen mainScreen].bounds.size.width

@interface ViewController () <UIGestureRecognizerDelegate> {
// 水平滚动的跑马灯
// 横向 跑马灯
JhtHorizontalMarquee *_horizontalMarquee;

// 上下滚动的跑马灯
// 纵向 跑马灯
JhtVerticalMarquee *_verticalMarquee;
// 是否暂停了上下滚动的跑马灯
// 是否暂停了纵向 跑马灯
BOOL _isPauseV;
}

Expand All @@ -34,7 +34,7 @@ @implementation ViewController

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// 如果暂停了,使用继续方式开启

if (_isPauseV) {
[_verticalMarquee marqueeOfSettingWithState:MarqueeContinue_V];
}
Expand All @@ -55,109 +55,132 @@ - (void)viewDidLoad {

self.automaticallyAdjustsScrollViewInsets = NO;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) {

#else
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
#endif

// 创建UI界面
[self createUI];
}



#pragma mark - UI
/** 创建UI界面 */
/** createUI */
- (void)createUI {
self.view.backgroundColor = [UIColor whiteColor];

self.title = @"JhtMarqueeDemo";

// 添加水平滚动的跑马灯
// 添加 横向 跑马灯
[self addHorizontalMarquee];

// 添加上下滚动的跑马灯
// 添加 纵向 跑马灯
[self addVerticalMarquee];
}


#pragma mark 水平滚动的跑马灯
/** 添加水平滚动的跑马灯 */
#pragma mark 横向 跑马灯
/** 添加 横向 跑马灯 */
- (void)addHorizontalMarquee {
_horizontalMarquee = [[JhtHorizontalMarquee alloc] initWithFrame:CGRectMake(0, 64 + 20, FrameW, 40) withSingleScrollDuration:10.0];
_horizontalMarquee.text = @"这是一个跑马灯View,测试一下好不好用,哈哈哈,😁👌😀 😁👌😀 😁👌😀 😁👌😀 哈哈哈哈! ";
[self.view addSubview:_horizontalMarquee];

// 给跑马灯添加点击手势
UITapGestureRecognizer *htap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(horizontalMarqueeTapGes:)];
[_horizontalMarquee addGestureRecognizer:htap];
}

- (void)horizontalMarqueeTapGes:(UITapGestureRecognizer *)ges {
NSLog(@"点击__水平__滚动的跑马灯啦!!!");
[_verticalMarquee marqueeOfSettingWithState:MarqueePause_V];
_isPauseV = YES;

[self.navigationController pushViewController:[[testVC alloc] init] animated:YES];
self.horizontalMarquee.text = @" 这是一个跑马灯View,测试一下好不好用,哈哈哈,😁👌😀 😁👌😀 😁👌😀 😁👌😀 哈哈哈哈! ";
[self.view addSubview:self.horizontalMarquee];
}


#pragma mark 上下滚动的跑马灯
/** 添加上下滚动的跑马灯 */
#pragma mark 纵向 跑马灯
/** 添加纵向 跑马灯 */
- (void)addVerticalMarquee {
_verticalMarquee = [[JhtVerticalMarquee alloc] initWithFrame:CGRectMake(10, 200, FrameW - 20, 45)];
[self.view addSubview:_verticalMarquee];
_verticalMarquee.backgroundColor = [UIColor yellowColor];
_verticalMarquee.verticalTextColor = [UIColor purpleColor];
// NSArray *soureArray = @[@"1. 谁曾从谁的青春里走过,留下了笑靥",
// @"2. 谁曾在谁的花季里停留,温暖了想念",
// @"3. 谁又从谁的雨季里消失,泛滥了眼泪",
// @"4. 人生路,路迢迢,谁道自古英雄多寂寥,若一朝,看透了,一身清风挣多少"
// ];
[self.view addSubview:self.verticalMarquee];

[self.verticalMarquee scrollWithCallbackBlock:^(JhtVerticalMarquee *view, NSInteger currentIndex) {
NSLog(@"滚动到第 %ld 条数据", (long)currentIndex);
}];
/*
NSArray *soureArray = @[@"1. 谁曾从谁的青春里走过,留下了笑靥",
@"2. 谁曾在谁的花季里停留,温暖了想念",
@"3. 谁又从谁的雨季里消失,泛滥了眼泪",
@"4. 人生路,路迢迢,谁道自古英雄多寂寥,若一朝,看透了,一身清风挣多少"
];
*/

NSString *str = @"谁曾在谁的花季里停留,温暖了想念";
// 创建NSMutableAttributedString
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str];
// 设置字体和设置字体的范围
[attrStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30.0f] range:NSMakeRange(0, 3)];
// 添加文字颜色
[attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4, 2)];
// 添加文字背景颜色
[attrStr addAttribute:NSBackgroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(7, 2)];
// 添加下划线
[attrStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(11, 5)];

NSArray *soureArray = @[@"1. 谁曾从谁的青春里走过,留下了笑靥",
attrStr,
@"3. 谁又从谁的雨季里消失,泛滥了眼泪",
@"4. 人生路,路迢迢,谁道自古英雄多寂寥,若一朝,看透了,一身清风挣多少"];

// _verticalMarquee.isCounterclockwise = YES;
_verticalMarquee.sourceArray = soureArray;
[_verticalMarquee scrollWithCallbackBlock:^(JhtVerticalMarquee *view, NSInteger currentIndex) {
NSLog(@"滚动到第 %ld 条数据", (long)currentIndex);
}];
self.verticalMarquee.sourceArray = soureArray;

// 开始滚动
[_verticalMarquee marqueeOfSettingWithState:MarqueeStart_V];
[self.verticalMarquee marqueeOfSettingWithState:MarqueeStart_V];
}



#pragma mark - Get
/** 横向 跑马灯 */
- (JhtHorizontalMarquee *)horizontalMarquee {
if (!_horizontalMarquee) {
_horizontalMarquee = [[JhtHorizontalMarquee alloc] initWithFrame:CGRectMake(0, 66, FrameW, 40) withSingleScrollDuration:10.0];

// 添加点击手势
UITapGestureRecognizer *htap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(horizontalMarqueeTapGes:)];
[_horizontalMarquee addGestureRecognizer:htap];
}

return _horizontalMarquee;
}

/** 纵向 跑马灯 */
- (JhtVerticalMarquee *)verticalMarquee {
if (!_verticalMarquee) {
_verticalMarquee = [[JhtVerticalMarquee alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(self.horizontalMarquee.frame) + 40, FrameW - 20, 45)];

_verticalMarquee.backgroundColor = [UIColor yellowColor];
_verticalMarquee.verticalTextColor = [UIColor purpleColor];

// 添加点击手势
UITapGestureRecognizer *vtap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(verticalMarqueeTapGes:)];
[_verticalMarquee addGestureRecognizer:vtap];
}

// 给跑马灯添加点击手势
UITapGestureRecognizer *vtap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(verticalMarqueeTapGes:)];
[_verticalMarquee addGestureRecognizer:vtap];
return _verticalMarquee;
}


#pragma mark Get Method
/** 点击 水平滚动跑马灯 触发方法 */
- (void)horizontalMarqueeTapGes:(UITapGestureRecognizer *)ges {
NSLog(@"点击__水平__滚动的跑马灯啦!!!");
[self.verticalMarquee marqueeOfSettingWithState:MarqueePause_V];
_isPauseV = YES;

[self.navigationController pushViewController:[[testVC alloc] init] animated:YES];
}

/** 点击 纵向滚动跑马灯 触发方法 */
- (void)verticalMarqueeTapGes:(UITapGestureRecognizer *)ges {
NSLog(@"点击__纵向__滚动的跑马灯_第 %ld 条数据啦!!!", (long)_verticalMarquee.currentIndex);
[_verticalMarquee marqueeOfSettingWithState:MarqueePause_V];
NSLog(@"点击__纵向__滚动的跑马灯_第 %ld 条数据啦!!!", (long)self.verticalMarquee.currentIndex);
[self.verticalMarquee marqueeOfSettingWithState:MarqueePause_V];
_isPauseV = YES;

[self.navigationController pushViewController:[[testVC alloc] init] animated:YES];
}




- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
Expand Down

0 comments on commit baf2725

Please sign in to comment.