Contents
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
#import <UIKit/UIKit.h>
@interface XYTabBar : UITabBar
@end
#import "XYTabBar.h"
@interface XYTabBar ()
@property (nonatomic, weak) UIButton *pulsButton;
@property (nonatomic, strong) UIControl *previousClickedTabbatButton;
@end
@implementation XYTabBar
- (UIButton *)pulsButton
{
if (_pulsButton == nil) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
[button sizeToFit];
[self addSubview:button];
_pulsButton = button;
}
return _pulsButton;
}
- (void)layoutSubviews
{
[super layoutSubviews];
NSInteger count = self.items.count + 1;
CGFloat w = self.xy_width / count;
CGFloat h = self.xy_height;
CGFloat x = 0;
int i = 0;
for (UIControl *tabBarButton in self.subviews) {
if (i == 0) {
self.previousClickedTabbatButton = tabBarButton;
}
if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
if (i == 2) {
i += 1;
}
x = i * w;
tabBarButton.frame = CGRectMake(x, 0, w, h);
i ++;
// 添加监听
[tabBarButton addTarget:self action:@selector(tabBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
}
// 发布按钮的位置
self.pulsButton.center = CGPointMake(self.xy_width * 0.5, self.xy_height * 0.5);
}
#pragma mark - 监听
/**
* 监听重复点击
*/
- (void)tabBarButtonClick:(UIControl *)tabBarButton
{
if (self.previousClickedTabbatButton == tabBarButton) {
[[NSNotificationCenter defaultCenter] postNotificationName:XYTabBarButtonDidClickRepeatNotification object:nil];
}
self.previousClickedTabbatButton = tabBarButton;
}
@end

图片

Contents