@@ -41,32 +41,28 @@ class SHCircleBarController: UITabBarController {
41
41
super. viewDidLoad ( )
42
42
let tabBar = SHCircleBar ( )
43
43
self . setValue ( tabBar, forKey: " tabBar " )
44
-
45
- }
46
- open override func viewWillAppear( _ animated: Bool ) {
47
- super. viewWillAppear ( animated)
48
- let tabWidth = self . view. bounds. width / CGFloat( self . tabBar. items!. count)
49
-
50
- circleView = UIView ( frame: CGRect ( x: tabWidth / 2 - 30 - self . view. safeAreaInsets. bottom, y: self . tabBar. frame. origin. y - 40 , width: 60 , height: 60 ) )
44
+
45
+ self . circleView = UIView ( frame: . zero)
51
46
circleView. layer. cornerRadius = 30
52
47
circleView. backgroundColor = . white
53
48
circleView. isUserInteractionEnabled = false
54
49
55
- circleImageView = UIImageView ( frame: self . circleView . bounds )
50
+ self . circleImageView = UIImageView ( frame: . zero )
56
51
circleImageView. layer. cornerRadius = 30
57
52
circleImageView. isUserInteractionEnabled = false
58
53
circleImageView. contentMode = . center
59
- circleImageView. image = image ( with: self . tabBar. selectedItem? . image, scaledTo: CGSize ( width: 30 , height: 30 ) )
60
-
54
+
61
55
circleView. addSubview ( circleImageView)
62
56
self . view. addSubview ( circleView)
63
-
57
+ let tabWidth = self . view. bounds. width / CGFloat( self . tabBar. items? . count ?? 4 )
58
+
59
+ circleView. frame = CGRect ( x: tabWidth / 2 - 30 , y: self . tabBar. frame. origin. y - 40 , width: 60 , height: 60 )
60
+ circleImageView. frame = self . circleView. bounds
64
61
}
65
-
66
- open override func viewDidAppear( _ animated: Bool ) {
67
- super. viewDidAppear ( animated)
68
-
69
-
62
+ open override func viewWillAppear( _ animated: Bool ) {
63
+ super. viewWillAppear ( animated)
64
+ circleImageView. image = image ( with: self . tabBar. selectedItem? . image ?? self . tabBar. items? . first? . image, scaledTo: CGSize ( width: 30 , height: 30 ) )
65
+
70
66
}
71
67
72
68
private var _barHeight : CGFloat = 74
@@ -105,10 +101,8 @@ class SHCircleBarController: UITabBarController {
105
101
}
106
102
107
103
open override func tabBar( _ tabBar: UITabBar , didSelect item: UITabBarItem ) {
108
- guard let idx = tabBar. items? . index ( of: item) else {
109
- return
110
- }
111
- if let controller = viewControllers ? [ idx] {
104
+ guard let idx = tabBar. items? . index ( of: item) else { return }
105
+ if idx != selectedIndex, let controller = viewControllers ? [ idx] {
112
106
shouldSelectOnTabBar = false
113
107
selectedIndex = idx
114
108
let tabWidth = self . view. bounds. width / CGFloat( self . tabBar. items!. count)
0 commit comments