diff --git a/.DS_Store b/.DS_Store index 10e02a6..7e1dafb 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/CircleBar/Classes/SHCircleBarController.swift b/CircleBar/Classes/SHCircleBarController.swift index a14b467..baa4542 100644 --- a/CircleBar/Classes/SHCircleBarController.swift +++ b/CircleBar/Classes/SHCircleBarController.swift @@ -41,32 +41,28 @@ class SHCircleBarController: UITabBarController { super.viewDidLoad() let tabBar = SHCircleBar() self.setValue(tabBar, forKey: "tabBar") - - } - open override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - let tabWidth = self.view.bounds.width / CGFloat(self.tabBar.items!.count) - - circleView = UIView(frame: CGRect(x: tabWidth / 2 - 30 - self.view.safeAreaInsets.bottom, y: self.tabBar.frame.origin.y - 40, width: 60, height: 60)) + + self.circleView = UIView(frame: .zero) circleView.layer.cornerRadius = 30 circleView.backgroundColor = .white circleView.isUserInteractionEnabled = false - circleImageView = UIImageView(frame: self.circleView.bounds) + self.circleImageView = UIImageView(frame: .zero) circleImageView.layer.cornerRadius = 30 circleImageView.isUserInteractionEnabled = false circleImageView.contentMode = .center - circleImageView.image = image(with: self.tabBar.selectedItem?.image, scaledTo: CGSize(width: 30, height: 30)) - + circleView.addSubview(circleImageView) self.view.addSubview(circleView) - + let tabWidth = self.view.bounds.width / CGFloat(self.tabBar.items?.count ?? 4) + + circleView.frame = CGRect(x: tabWidth / 2 - 30, y: self.tabBar.frame.origin.y - 40, width: 60, height: 60) + circleImageView.frame = self.circleView.bounds } - - open override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - - + open override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + circleImageView.image = image(with: self.tabBar.selectedItem?.image ?? self.tabBar.items?.first?.image, scaledTo: CGSize(width: 30, height: 30)) + } private var _barHeight: CGFloat = 74 @@ -105,10 +101,8 @@ class SHCircleBarController: UITabBarController { } open override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) { - guard let idx = tabBar.items?.index(of: item) else { - return - } - if let controller = viewControllers?[idx] { + guard let idx = tabBar.items?.index(of: item) else { return } + if idx != selectedIndex, let controller = viewControllers?[idx] { shouldSelectOnTabBar = false selectedIndex = idx let tabWidth = self.view.bounds.width / CGFloat(self.tabBar.items!.count) diff --git a/Example/CircleBar.xcworkspace/xcuserdata/perteadi.xcuserdatad/UserInterfaceState.xcuserstate b/Example/CircleBar.xcworkspace/xcuserdata/perteadi.xcuserdatad/UserInterfaceState.xcuserstate index dd03d0c..51f59da 100644 Binary files a/Example/CircleBar.xcworkspace/xcuserdata/perteadi.xcuserdatad/UserInterfaceState.xcuserstate and b/Example/CircleBar.xcworkspace/xcuserdata/perteadi.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Example/CircleBar.xcworkspace/xcuserdata/perteadi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Example/CircleBar.xcworkspace/xcuserdata/perteadi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..ed9a9b4 --- /dev/null +++ b/Example/CircleBar.xcworkspace/xcuserdata/perteadi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/Example/CircleBar/.DS_Store b/Example/CircleBar/.DS_Store new file mode 100644 index 0000000..beb3449 Binary files /dev/null and b/Example/CircleBar/.DS_Store differ diff --git a/README.md b/README.md index 7a03412..76af54f 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,9 @@ pod 'CircleBar' # Usage 1. Create a new `UITabBarController` in your storyboard or nib. -2. Set the class of the `UITabBarController` to `SHTabBarController` in your Storyboard or nib. +2. Set the class of the `UITabBarController` to `SHCircleController` in your Storyboard or nib. -3. Set the class of the `UITabBar` of `SHTabBarController` to `SHTabBar` in your Storyboard or nib. +3. Set the class of the `UITabBar` of `SHTabBarController` to `SHCircleBar` in your Storyboard or nib. 4. Add a custom image icon and title for `UITabBarItem` of each child `UIViewContrroller`.