From f15905f8249fb7221571094e5881293f78a3cba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cgokulnair2001=E2=80=9D?= <“gokulnair.2001@gmail.com”> Date: Tue, 2 Feb 2021 16:33:14 +0530 Subject: [PATCH 1/5] Added Haptic Feedback --- CircleBar/Classes/SHCircleBar.swift | 17 +++++++------- CircleBar/Classes/SHCircleBarController.swift | 4 ++-- Example/CircleBar/Main.storyboard | 22 +++++++++++-------- Example/CircleBar/ViewController.swift | 1 - Example/Pods/Pods.xcodeproj/project.pbxproj | 1 + Haptic Feedback.swift | 18 +++++++++++++++ 6 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 Haptic Feedback.swift diff --git a/CircleBar/Classes/SHCircleBar.swift b/CircleBar/Classes/SHCircleBar.swift index 8830e84..90dd22e 100644 --- a/CircleBar/Classes/SHCircleBar.swift +++ b/CircleBar/Classes/SHCircleBar.swift @@ -26,10 +26,9 @@ import UIKit required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) customInit() - } override func draw(_ rect: CGRect) { - let fillColor: UIColor = .white + let fillColor: UIColor = .black tabWidth = self.bounds.width / CGFloat(self.items!.count) let bezPath = drawPath(for: index) @@ -50,7 +49,7 @@ import UIKit mask.add(bezAnimation, forKey: nil) } self.layer.mask = mask - + } func select(itemAt: Int, animated: Bool) { @@ -68,15 +67,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) @@ -84,6 +83,8 @@ import UIKit bezPath.append(UIBezierPath(rect: self.bounds)) return bezPath } - - + func hapticFeedback(){ + let generator = UINotificationFeedbackGenerator() + generator.notificationOccurred(.success) + } } diff --git a/CircleBar/Classes/SHCircleBarController.swift b/CircleBar/Classes/SHCircleBarController.swift index baa4542..4125ca3 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,7 @@ class SHCircleBarController: UITabBarController { } guard let tabBar = tabBar as? SHCircleBar, let index = viewControllers?.index(of: newValue) else {return} tabBar.select(itemAt: index, animated: true) + tabBar.hapticFeedback() } } @@ -62,7 +63,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 diff --git a/Example/CircleBar/Main.storyboard b/Example/CircleBar/Main.storyboard index ffbb369..3f64240 100644 --- a/Example/CircleBar/Main.storyboard +++ b/Example/CircleBar/Main.storyboard @@ -1,10 +1,9 @@ - - - - + + - + + @@ -16,8 +15,8 @@ - + @@ -54,8 +53,8 @@ - + @@ -72,8 +71,8 @@ - + @@ -90,8 +89,8 @@ - + @@ -102,6 +101,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; diff --git a/Haptic Feedback.swift b/Haptic Feedback.swift new file mode 100644 index 0000000..8504de6 --- /dev/null +++ b/Haptic Feedback.swift @@ -0,0 +1,18 @@ +// +// Haptic Feedback.swift +// CircleBar +// +// Created by Gokul Nair on 02/02/21. +// + +import Foundation + +class HapticFeedback{ + //Declaring class as static + static let Feedback = HapticFeedback() + func hapticFeedback(){ + print("feedback") + let generator = UINotificationFeedbackGenerator() + generator.notificationOccurred(.success) + } +} From f217256e82841ae663d05fb129015c5d0c259a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cgokulnair2001=E2=80=9D?= <“gokulnair.2001@gmail.com”> Date: Tue, 2 Feb 2021 16:35:29 +0530 Subject: [PATCH 2/5] minor bug solved --- CircleBar/Classes/SHCircleBar.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CircleBar/Classes/SHCircleBar.swift b/CircleBar/Classes/SHCircleBar.swift index 90dd22e..5ea8fe6 100644 --- a/CircleBar/Classes/SHCircleBar.swift +++ b/CircleBar/Classes/SHCircleBar.swift @@ -28,7 +28,7 @@ import UIKit customInit() } override func draw(_ rect: CGRect) { - let fillColor: UIColor = .black + let fillColor: UIColor = .white tabWidth = self.bounds.width / CGFloat(self.items!.count) let bezPath = drawPath(for: index) From 4976b1b64d769eb37ef6bb54e387699f1ca837e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cgokulnair2001=E2=80=9D?= <“gokulnair.2001@gmail.com”> Date: Wed, 3 Feb 2021 08:29:51 +0530 Subject: [PATCH 3/5] Layout fix --- CircleBar/Classes/SHCircleBarController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CircleBar/Classes/SHCircleBarController.swift b/CircleBar/Classes/SHCircleBarController.swift index 4125ca3..0e9e8d2 100644 --- a/CircleBar/Classes/SHCircleBarController.swift +++ b/CircleBar/Classes/SHCircleBarController.swift @@ -87,7 +87,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() From 6731f01b0a897f6a09300cbf1c9a46f8685b140f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cgokulnair2001=E2=80=9D?= <“gokulnair.2001@gmail.com”> Date: Sat, 6 Feb 2021 00:46:09 +0530 Subject: [PATCH 4/5] Required Changes --- CircleBar/Classes/SHCircleBar.swift | 16 +++++++++++++--- CircleBar/Classes/SHCircleBarController.swift | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CircleBar/Classes/SHCircleBar.swift b/CircleBar/Classes/SHCircleBar.swift index 5ea8fe6..6e326b0 100644 --- a/CircleBar/Classes/SHCircleBar.swift +++ b/CircleBar/Classes/SHCircleBar.swift @@ -23,6 +23,12 @@ import UIKit customInit() } + @IBInspectable var HapticFeedback:Bool = false { + didSet{ + self.hapticFeedback(status: HapticFeedback) + } + } + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) customInit() @@ -83,8 +89,12 @@ import UIKit bezPath.append(UIBezierPath(rect: self.bounds)) return bezPath } - func hapticFeedback(){ - let generator = UINotificationFeedbackGenerator() - generator.notificationOccurred(.success) + + func hapticFeedback(status: Bool){ + if status == true { + let generator = UINotificationFeedbackGenerator() + generator.notificationOccurred(.success) + print("hello") + }else{ } } } diff --git a/CircleBar/Classes/SHCircleBarController.swift b/CircleBar/Classes/SHCircleBarController.swift index 0e9e8d2..4bffaf0 100644 --- a/CircleBar/Classes/SHCircleBarController.swift +++ b/CircleBar/Classes/SHCircleBarController.swift @@ -21,7 +21,7 @@ class SHCircleBarController: UITabBarController { } guard let tabBar = tabBar as? SHCircleBar, let index = viewControllers?.index(of: newValue) else {return} tabBar.select(itemAt: index, animated: true) - tabBar.hapticFeedback() + tabBar.hapticFeedback(status: tabBar.HapticFeedback) } } From 148cae2c2e80d656c8febed97691f399a26094f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cgokulnair2001=E2=80=9D?= <“gokulnair.2001@gmail.com”> Date: Mon, 8 Feb 2021 20:32:25 +0530 Subject: [PATCH 5/5] Final Changes Done --- CircleBar/Classes/SHCircleBar.swift | 9 +++------ CircleBar/Classes/SHCircleBarController.swift | 4 +++- Example/CircleBar/Main.storyboard | 4 ++++ Haptic Feedback.swift | 18 ------------------ 4 files changed, 10 insertions(+), 25 deletions(-) delete mode 100644 Haptic Feedback.swift diff --git a/CircleBar/Classes/SHCircleBar.swift b/CircleBar/Classes/SHCircleBar.swift index 6e326b0..93ca030 100644 --- a/CircleBar/Classes/SHCircleBar.swift +++ b/CircleBar/Classes/SHCircleBar.swift @@ -23,9 +23,9 @@ import UIKit customInit() } - @IBInspectable var HapticFeedback:Bool = false { + @IBInspectable var hasHapticFeedback:Bool = false { didSet{ - self.hapticFeedback(status: HapticFeedback) + self.hapticFeedback() } } @@ -90,11 +90,8 @@ import UIKit return bezPath } - func hapticFeedback(status: Bool){ - if status == true { + func hapticFeedback(){ let generator = UINotificationFeedbackGenerator() generator.notificationOccurred(.success) - print("hello") - }else{ } } } diff --git a/CircleBar/Classes/SHCircleBarController.swift b/CircleBar/Classes/SHCircleBarController.swift index 4bffaf0..fbe1173 100644 --- a/CircleBar/Classes/SHCircleBarController.swift +++ b/CircleBar/Classes/SHCircleBarController.swift @@ -21,7 +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) - tabBar.hapticFeedback(status: tabBar.HapticFeedback) + if tabBar.hasHapticFeedback { + tabBar.hapticFeedback() + } } } diff --git a/Example/CircleBar/Main.storyboard b/Example/CircleBar/Main.storyboard index 3f64240..e0beb81 100644 --- a/Example/CircleBar/Main.storyboard +++ b/Example/CircleBar/Main.storyboard @@ -34,6 +34,10 @@ + + + + diff --git a/Haptic Feedback.swift b/Haptic Feedback.swift deleted file mode 100644 index 8504de6..0000000 --- a/Haptic Feedback.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// Haptic Feedback.swift -// CircleBar -// -// Created by Gokul Nair on 02/02/21. -// - -import Foundation - -class HapticFeedback{ - //Declaring class as static - static let Feedback = HapticFeedback() - func hapticFeedback(){ - print("feedback") - let generator = UINotificationFeedbackGenerator() - generator.notificationOccurred(.success) - } -}