diff --git a/CircleBar/Classes/SHCircleBar.swift b/CircleBar/Classes/SHCircleBar.swift index 8830e84..93ca030 100644 --- a/CircleBar/Classes/SHCircleBar.swift +++ b/CircleBar/Classes/SHCircleBar.swift @@ -23,10 +23,15 @@ import UIKit customInit() } + @IBInspectable var hasHapticFeedback:Bool = false { + didSet{ + self.hapticFeedback() + } + } + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) customInit() - } override func draw(_ rect: CGRect) { let fillColor: UIColor = .white @@ -50,7 +55,7 @@ import UIKit mask.add(bezAnimation, forKey: nil) } self.layer.mask = mask - + } func select(itemAt: Int, animated: Bool) { @@ -68,15 +73,15 @@ import UIKit } private func drawPath(for index: CGFloat) -> UIBezierPath { let bezPath = UIBezierPath() - + let firstPoint = CGPoint(x: (index * tabWidth) - 25, y: 0) let firstPointFirstCurve = CGPoint(x: ((tabWidth * index) + tabWidth / 4), y: 0) let firstPointSecondCurve = CGPoint(x: ((index * tabWidth) - 25) + tabWidth / 8, y: 52) - + let middlePoint = CGPoint(x: (tabWidth * index) + tabWidth / 2, y: 55) let middlePointFirstCurve = CGPoint(x: (((tabWidth * index) + tabWidth) - tabWidth / 8) + 25, y: 52) let middlePointSecondCurve = CGPoint(x: (((tabWidth * index) + tabWidth) - tabWidth / 4), y: 0) - + let lastPoint = CGPoint(x: (tabWidth * index) + tabWidth + 25, y: 0) bezPath.move(to: firstPoint) bezPath.addCurve(to: middlePoint, controlPoint1: firstPointFirstCurve, controlPoint2: firstPointSecondCurve) @@ -85,5 +90,8 @@ import UIKit return bezPath } - + func hapticFeedback(){ + let generator = UINotificationFeedbackGenerator() + generator.notificationOccurred(.success) + } } diff --git a/CircleBar/Classes/SHCircleBarController.swift b/CircleBar/Classes/SHCircleBarController.swift index baa4542..fbe1173 100644 --- a/CircleBar/Classes/SHCircleBarController.swift +++ b/CircleBar/Classes/SHCircleBarController.swift @@ -9,7 +9,7 @@ import UIKit class SHCircleBarController: UITabBarController { - + fileprivate var shouldSelectOnTabBar = true private var circleView : UIView! private var circleImageView: UIImageView! @@ -21,6 +21,9 @@ class SHCircleBarController: UITabBarController { } guard let tabBar = tabBar as? SHCircleBar, let index = viewControllers?.index(of: newValue) else {return} tabBar.select(itemAt: index, animated: true) + if tabBar.hasHapticFeedback { + tabBar.hapticFeedback() + } } } @@ -62,7 +65,6 @@ class SHCircleBarController: UITabBarController { 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 @@ -87,7 +89,10 @@ class SHCircleBarController: UITabBarController { self.tabBar.frame = tabFrame tabBar.setNeedsLayout() } - + open override func viewDidLayoutSubviews() { + super.viewDidLayoutSubviews() + self.selectedIndex = 1 + } open override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() updateTabBarFrame() diff --git a/Example/CircleBar/Main.storyboard b/Example/CircleBar/Main.storyboard index ffbb369..e0beb81 100644 --- a/Example/CircleBar/Main.storyboard +++ b/Example/CircleBar/Main.storyboard @@ -1,10 +1,9 @@ - - - - + + - + + @@ -16,8 +15,8 @@ - + @@ -35,6 +34,10 @@ + + + + @@ -54,8 +57,8 @@ - + @@ -72,8 +75,8 @@ - + @@ -90,8 +93,8 @@ - + @@ -102,6 +105,11 @@ + + + + + diff --git a/Example/CircleBar/ViewController.swift b/Example/CircleBar/ViewController.swift index c0ca10c..d71bc05 100644 --- a/Example/CircleBar/ViewController.swift +++ b/Example/CircleBar/ViewController.swift @@ -12,7 +12,6 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 78bd096..b31924d 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -329,6 +329,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 7DB346D0F39D3F0E887471402A8071AB;