Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Haptic Feedback : Enhance User Experience #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions CircleBar/Classes/SHCircleBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import UIKit
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
customInit()

}
override func draw(_ rect: CGRect) {
let fillColor: UIColor = .white
Expand All @@ -50,7 +49,7 @@ import UIKit
mask.add(bezAnimation, forKey: nil)
}
self.layer.mask = mask

}

func select(itemAt: Int, animated: Bool) {
Expand All @@ -68,22 +67,24 @@ 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)
bezPath.addCurve(to: lastPoint, controlPoint1: middlePointFirstCurve, controlPoint2: middlePointSecondCurve)
bezPath.append(UIBezierPath(rect: self.bounds))
return bezPath
}


func hapticFeedback(){
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success)
}
}
9 changes: 6 additions & 3 deletions CircleBar/Classes/SHCircleBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

class SHCircleBarController: UITabBarController {

fileprivate var shouldSelectOnTabBar = true
private var circleView : UIView!
private var circleImageView: UIImageView!
Expand All @@ -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()
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
22 changes: 13 additions & 9 deletions Example/CircleBar/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BgY-q2-TDs">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BgY-q2-TDs">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -16,8 +15,8 @@
<view key="view" contentMode="scaleToFill" id="6JG-08-P4f">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.45098039220000002" green="0.34509803919999998" blue="0.96078431369999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="Ni4-BZ-rv1"/>
<color key="backgroundColor" red="0.45098039220000002" green="0.34509803919999998" blue="0.96078431369999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<tabBarItem key="tabBarItem" title="View 1" image="apple" id="6WL-HR-obU">
<color key="badgeColor" red="0.90588235289999997" green="0.42745098040000001" blue="0.17254901959999999" alpha="1" colorSpace="calibratedRGB"/>
Expand Down Expand Up @@ -54,8 +53,8 @@
<view key="view" contentMode="scaleToFill" id="gK5-XA-reX">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" name="systemPinkColor" catalog="System" colorSpace="catalog"/>
<viewLayoutGuide key="safeArea" id="tU0-ki-joq"/>
<color key="backgroundColor" name="systemPinkColor" catalog="System" colorSpace="catalog"/>
</view>
<tabBarItem key="tabBarItem" title="View 2" image="approval" id="0S5-D7-S5D">
<color key="badgeColor" red="0.38823529410000002" green="0.26274509800000001" blue="0.95294117649999999" alpha="1" colorSpace="calibratedRGB"/>
Expand All @@ -72,8 +71,8 @@
<view key="view" contentMode="scaleToFill" id="yF0-it-ruw">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.90588235289999997" green="0.42745098040000001" blue="0.17254901959999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="0gA-K9-yFr"/>
<color key="backgroundColor" red="0.90588235289999997" green="0.42745098040000001" blue="0.17254901959999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<tabBarItem key="tabBarItem" title="View 3" image="bell" id="yRC-Jh-mdH">
<color key="badgeColor" name="systemPinkColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -90,8 +89,8 @@
<view key="view" contentMode="scaleToFill" id="fSt-rT-knK">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.3411764706" green="0.72549019609999998" blue="0.60784313729999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="XhL-vf-R9Z"/>
<color key="backgroundColor" red="0.3411764706" green="0.72549019609999998" blue="0.60784313729999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<tabBarItem key="tabBarItem" title="View 4" image="about" id="XKK-fW-YWm">
<color key="badgeColor" name="systemPinkColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -102,6 +101,11 @@
<point key="canvasLocation" x="4014" y="134"/>
</scene>
</scenes>
<designables>
<designable name="hhh-Wy-Ffr">
<size key="intrinsicContentSize" width="-1" height="49"/>
</designable>
</designables>
<resources>
<image name="about" width="30" height="30"/>
<image name="apple" width="30" height="30"/>
Expand Down
1 change: 0 additions & 1 deletion Example/CircleBar/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Haptic Feedback.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}