BBATabBar.h
3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// BBATabbar.h
// BBAUIKit
//
// Created by performance on 2018/8/29.
// Copyright © 2018年 Baidu. All rights reserved.
//
#import <UIKit/UIKit.h>
/*
--------------------------------------------------------------------
| ___ | ___ | | ___ | ___ |
magin | | 1 | | | 2 | | 3 | | 4 | | | 5 | | magin
| |___| | |___| | | |___| | |___| |
| | | | | |
--------------------------------------------------------------------
3 为自定义大小
1 2 4 5的响应区域均分
图标1/2之间的间隔和2/3的间隔一致, 故图标2未居中
---------------------------------------------------------------------------
---------------------------------------------------------------
| ___ | ___ | | ___ | ___ |
magin | | 1 | | | 2 | | 3 | | 4 | | | 5 | | magin
| |___| | |___| | | |___| | |___| |
| | | | | |
---------------------------------------------------------------
重构后,调整frame布局使icon位于frame居中
1. 减去左右边距与自定义响应区Size后,均分响应区
2. 确定左右两个元素icon的中心位置
3. 保证icon间间距一致,确定其他icon中心位置
4. 根据间隔确定实际响应区
*/
@interface BBATabBar : UIView
@property (nonatomic, strong, nonnull) UIImage *backgroundImage;
@property (nonatomic, strong, nonnull) UIImage *loadingItemImage;
@property (nonatomic, strong, nonnull) UIColor *normalTintColor;
@property (nonatomic, strong, nonnull) UIColor *highlightTintColor;
@property (nonatomic, strong, nonnull) UIColor *seletedTintColor;
@property (nonatomic, assign) CGRect extraHitRegion;//自定义点击区域
/// 11.25拓展,不规则点击区域
@property (nonatomic, strong, nonnull) UIBezierPath *extraHitPath;
@property (nonatomic, assign, readonly) NSInteger selectedIndex;
//事件响应
- (CGRect)itemRect:(NSInteger)index;
//图标区域
- (CGRect)iconRect:(NSInteger)index;
//更新items
- (void)updateWithItems:(nonnull NSArray*)items selected:(void (^ __nullable)(NSInteger index))completion;
//重置tab bar底部与主window底部对齐
- (void)resetTabBarOriginY;
#pragma mark - 更新
/**
之前TabBarController通过API更新TabBar的Index, TabBar点击也更新Index, 数据流双向传递可能导致TabBarController与TabBar中Index不同步问题
现保持单向数据流, 只能通过updateWithIndex更新TabBar的Index, TabBar点击传递点击事件,TabBarController切换VC后再通过API更新TabBar的Index, 保证TabBarController与TabBar中Index同步
*/
//index:当前高亮的项
- (void)updateWithIndex:(NSInteger)index;
//更新子视图布局(响应区,布局,文案展示/隐藏)
- (void)updateItemViews;
//更新loading状态
- (void)updateLoading;
//更新飘新
- (void)updateBadge;
//更新所有状态
- (void)update;
#pragma mark - 飘新
//设置飘新红点
- (void)setBadgeDotShow:(BOOL)show index:(NSInteger)index;
//设置飘新数字
- (void)setBadgeNumber:(NSInteger)badgeNumber index:(NSInteger)index;
//设置飘新文字
- (void)setBadgeValue:(NSString *_Nonnull)badgeValue index:(NSInteger)index;
//清除飘新
- (void)removeBadgeWithIndex:(NSInteger)index;
#pragma mark - debug
#ifdef _DEBUGMENU
//展示icon的边框(debug 定位使用)
@property (nonatomic, assign) bool debug_showIconRect;
//展示响应区域的边框(debug 定位使用)
@property (nonatomic, assign) bool debug_showResponseRect;
#endif
@end