@@ -41,32 +41,28 @@ class SHCircleBarController: UITabBarController {
4141 super. viewDidLoad ( )
4242 let tabBar = SHCircleBar ( )
4343 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)
5146 circleView. layer. cornerRadius = 30
5247 circleView. backgroundColor = . white
5348 circleView. isUserInteractionEnabled = false
5449
55- circleImageView = UIImageView ( frame: self . circleView . bounds )
50+ self . circleImageView = UIImageView ( frame: . zero )
5651 circleImageView. layer. cornerRadius = 30
5752 circleImageView. isUserInteractionEnabled = false
5853 circleImageView. contentMode = . center
59- circleImageView. image = image ( with: self . tabBar. selectedItem? . image, scaledTo: CGSize ( width: 30 , height: 30 ) )
60-
54+
6155 circleView. addSubview ( circleImageView)
6256 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
6461 }
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+
7066 }
7167
7268 private var _barHeight : CGFloat = 74
@@ -105,10 +101,8 @@ class SHCircleBarController: UITabBarController {
105101 }
106102
107103 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] {
112106 shouldSelectOnTabBar = false
113107 selectedIndex = idx
114108 let tabWidth = self . view. bounds. width / CGFloat( self . tabBar. items!. count)
0 commit comments