Skip to content

Commit fdd7a10

Browse files
committed
fixes issue #4 & #5
1 parent 10cea1b commit fdd7a10

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

.DS_Store

0 Bytes
Binary file not shown.

CircleBar/Classes/SHCircleBarController.swift

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "0"
4+
version = "2.0">
5+
</Bucket>

Example/CircleBar/.DS_Store

6 KB
Binary file not shown.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ pod 'CircleBar'
5959
# Usage
6060
1. Create a new `UITabBarController` in your storyboard or nib.
6161

62-
2. Set the class of the `UITabBarController` to `SHTabBarController` in your Storyboard or nib.
62+
2. Set the class of the `UITabBarController` to `SHCircleController` in your Storyboard or nib.
6363

64-
3. Set the class of the `UITabBar` of `SHTabBarController` to `SHTabBar` in your Storyboard or nib.
64+
3. Set the class of the `UITabBar` of `SHTabBarController` to `SHCircleBar` in your Storyboard or nib.
6565

6666
4. Add a custom image icon and title for `UITabBarItem` of each child `UIViewContrroller`.
6767

0 commit comments

Comments
 (0)