chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:35:01 +08:00
commit a2e318a963
2974 changed files with 158180 additions and 0 deletions
@@ -0,0 +1,15 @@
//
// TLScannerBackgroundView.h
// TLChat
//
// Created by 李伯坤 on 16/3/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLScannerBackgroundView : UIView
- (void)addMasonryWithContainView:(UIView *)containView;
@end
@@ -0,0 +1,96 @@
//
// TLScannerBackgroundView.m
// TLChat
//
// Created by 李伯坤 on 16/3/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLScannerBackgroundView.h"
@interface TLScannerBackgroundView ()
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIView *btmView;
@property (nonatomic, strong) UIView *leftView;
@property (nonatomic, strong) UIView *rightView;
@end
@implementation TLScannerBackgroundView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self addSubview:self.topView];
[self addSubview:self.btmView];
[self addSubview:self.leftView];
[self addSubview:self.rightView];
}
return self;
}
#pragma mark - Public Methods -
- (void)addMasonryWithContainView:(UIView *)containView
{
UIView *scannerView = containView;
[self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.and.right.mas_equalTo(self);
make.bottom.mas_equalTo(scannerView.mas_top);
}];
[self.btmView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.and.bottom.mas_equalTo(self);
make.top.mas_equalTo(scannerView.mas_bottom);
}];
[self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self);
make.right.mas_equalTo(scannerView.mas_left);
make.top.mas_equalTo(self.topView.mas_bottom);
make.bottom.mas_equalTo(self.btmView.mas_top);
}];
[self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(scannerView.mas_right);
make.right.mas_equalTo(self);
make.top.mas_equalTo(self.topView.mas_bottom);
make.bottom.mas_equalTo(self.btmView.mas_top);
}];
}
#pragma mark - Getter -
- (UIView *)topView
{
if (_topView == nil) {
_topView = [[UIView alloc] init];
[_topView setBackgroundColor:[UIColor colorBlackAlphaScannerBG]];
}
return _topView;
}
- (UIView *)btmView
{
if (_btmView == nil) {
_btmView = [[UIView alloc] init];
[_btmView setBackgroundColor:[UIColor colorBlackAlphaScannerBG]];
}
return _btmView;
}
- (UIView *)leftView
{
if (_leftView == nil) {
_leftView = [[UIView alloc] init];
[_leftView setBackgroundColor:[UIColor colorBlackAlphaScannerBG]];
}
return _leftView;
}
- (UIView *)rightView
{
if (_rightView == nil) {
_rightView = [[UIView alloc] init];
[_rightView setBackgroundColor:[UIColor colorBlackAlphaScannerBG]];
}
return _rightView;
}
@end
@@ -0,0 +1,33 @@
//
// TLScannerButton.h
// TLChat
//
// Created by 李伯坤 on 16/2/25.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSUInteger, TLScannerType) {
TLScannerTypeQR = 1, // 扫一扫 - 二维码
TLScannerTypeCover, // 扫一扫 - 封面
TLScannerTypeStreet, // 扫一扫 - 街景
TLScannerTypeTranslate, // 扫一扫 - 翻译
};
@interface TLScannerButton : UIButton
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *iconPath;
@property (nonatomic, strong) NSString *iconHLPath;
@property (nonatomic, assign) TLScannerType type;
@property (nonatomic, assign) NSUInteger msgNumber;
- (id)initWithType:(TLScannerType)type title:(NSString *)title iconPath:(NSString *)iconPath iconHLPath:(NSString *)iconHLPath;
@end
@@ -0,0 +1,94 @@
//
// TLScannerButton.m
// TLChat
//
// Created by 李伯坤 on 16/2/25.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLScannerButton.h"
@interface TLScannerButton ()
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *textLabel;
@end
@implementation TLScannerButton
- (id)initWithType:(TLScannerType)type title:(NSString *)title iconPath:(NSString *)iconPath iconHLPath:(NSString *)iconHLPath
{
if (self = [super init]) {
[self addSubview:self.iconImageView];
[self addSubview:self.textLabel];
[self p_addMasonry];
self.type = type;
self.title = title;
self.iconPath = iconPath;
self.iconHLPath = iconHLPath;
}
return self;
}
- (void)setTitle:(NSString *)title
{
_title = title;
[self.textLabel setText:title];
}
- (void)setIconPath:(NSString *)iconPath
{
_iconPath = iconPath;
[self.iconImageView setImage:[UIImage imageNamed:iconPath]];
}
- (void)setIconHLPath:(NSString *)iconHLPath
{
_iconHLPath = iconHLPath;
[self.iconImageView setHighlightedImage:[UIImage imageNamed:iconHLPath]];
}
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
[self.iconImageView setHighlighted:selected];
[self.textLabel setHighlighted:selected];
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.and.right.mas_equalTo(self);
make.height.mas_equalTo(self.iconImageView.mas_width);
}];
[self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.mas_equalTo(self);
make.bottom.mas_equalTo(self);
}];
}
#pragma mark - Getter -
- (UIImageView *)iconImageView
{
if (_iconImageView == nil) {
_iconImageView = [[UIImageView alloc] init];
}
return _iconImageView;
}
- (UILabel *)textLabel
{
if (_textLabel == nil) {
_textLabel = [[UILabel alloc] init];
[_textLabel setFont:[UIFont systemFontOfSize:12.0f]];
[_textLabel setTextAlignment:NSTextAlignmentCenter];
[_textLabel setTextColor:[UIColor whiteColor]];
[_textLabel setHighlightedTextColor:[UIColor colorGreenDefault]];
}
return _textLabel;
}
@end
@@ -0,0 +1,22 @@
//
// TLScannerView.h
// TLChat
//
// Created by 李伯坤 on 16/3/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TLScannerView : UIView
/**
* 隐藏扫描指示器,默认NO
*/
@property (nonatomic, assign) BOOL hiddenScannerIndicator;
- (void)startScanner;
- (void)stopScanner;
@end
@@ -0,0 +1,174 @@
//
// TLScannerView.m
// TLChat
//
// Created by 李伯坤 on 16/3/4.
// Copyright © 2016年 李伯坤. All rights reserved.
//
#import "TLScannerView.h"
@interface TLScannerView ()
{
NSTimer *timer;
}
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *topLeftView;
@property (nonatomic, strong) UIImageView *topRightView;
@property (nonatomic, strong) UIImageView *btmLeftView;
@property (nonatomic, strong) UIImageView *btmRightView;
@property (nonatomic, strong) UIImageView *scannerLine;
@end
@implementation TLScannerView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setClipsToBounds:YES];
[self addSubview:self.bgView];
[self addSubview:self.topLeftView];
[self addSubview:self.topRightView];
[self addSubview:self.btmLeftView];
[self addSubview:self.btmRightView];
[self addSubview:self.scannerLine];
[self p_addMasonry];
}
return self;
}
#pragma mark - Public Methods -
- (void)startScanner
{
[self stopScanner];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 / 60 block:^(NSTimer *timer) {
if (self.hiddenScannerIndicator) {
return;
}
self.scannerLine.centerX = self.bgView.centerX;
self.scannerLine.width = self.bgView.width * 1.4;
self.scannerLine.height = 10;
if (self.scannerLine.y + self.scannerLine.height >= self.height) {
self.scannerLine.y = 0;
}
else {
self.scannerLine.y ++;
}
} repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
- (void)stopScanner
{
if (timer) {
[timer invalidate];
timer = nil;
}
}
- (void)setHiddenScannerIndicator:(BOOL)hiddenScannerIndicator
{
if (hiddenScannerIndicator == _hiddenScannerIndicator) {
return;
}
if (hiddenScannerIndicator) {
self.scannerLine.y = 0;
[self.scannerLine setHidden:YES];
_hiddenScannerIndicator = hiddenScannerIndicator;
}
else {
_hiddenScannerIndicator = hiddenScannerIndicator;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.scannerLine.y = 0;
[self.scannerLine setHidden:hiddenScannerIndicator];
});
}
}
#pragma mark - Private Methods -
- (void)p_addMasonry
{
[_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
[_topLeftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.top.mas_equalTo(self);
make.width.and.height.mas_lessThanOrEqualTo(self);
}];
[_topRightView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.and.top.mas_equalTo(self);
make.width.and.height.mas_lessThanOrEqualTo(self);
}];
[_btmLeftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.bottom.mas_equalTo(self);
make.width.and.height.mas_lessThanOrEqualTo(self);
}];
[_btmRightView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.and.bottom.mas_equalTo(self);
make.width.and.height.mas_lessThanOrEqualTo(self);
}];
}
#pragma mark - Getter -
- (UIView *)bgView
{
if (_bgView == nil) {
_bgView = [[UIView alloc] init];
[_bgView setBackgroundColor:[UIColor clearColor]];
[_bgView.layer setMasksToBounds:YES];
[_bgView.layer setBorderWidth:BORDER_WIDTH_1PX];
[_bgView.layer setBorderColor:[UIColor whiteColor].CGColor];
}
return _bgView;
}
- (UIImageView *)topLeftView
{
if (_topLeftView == nil) {
_topLeftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scanner_top_left"]];
}
return _topLeftView;
}
- (UIImageView *)topRightView
{
if (_topRightView == nil) {
_topRightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scanner_top_right"]];
}
return _topRightView;
}
- (UIImageView *)btmLeftView
{
if (_btmLeftView == nil) {
_btmLeftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scanner_bottom_left"]];
}
return _btmLeftView;
}
- (UIImageView *)btmRightView
{
if (_btmRightView == nil) {
_btmRightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scanner_bottom_right"]];
}
return _btmRightView;
}
- (UIImageView *)scannerLine
{
if (_scannerLine == nil) {
_scannerLine = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"scanner_line"]];
[_scannerLine setFrame:CGRectZero];
}
return _scannerLine;
}
@end