Skip to content

Commit

Permalink
softhausHQ#12 Issue Resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
kamrul-cse committed Jul 29, 2021
1 parent 1e64cf7 commit 03ce6cb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
44 changes: 28 additions & 16 deletions CircleBar/Classes/SHCircleBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import UIKit
private var selectedImage: UIImage?
private var previousIndex: CGFloat = 0

private let maskLayer = CAShapeLayer()
private let shadowLayer = CAShapeLayer()
private let maskedView = UIView()

override init(frame: CGRect) {
super.init(frame: frame)
customInit()
Expand All @@ -27,7 +31,6 @@ import UIKit
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
customInit()

}

open override func draw(_ rect: CGRect) {
Expand All @@ -46,33 +49,41 @@ extension SHCircleBar {
}

private func drawCurve() {
let fillColor: UIColor = .white
tabWidth = self.bounds.width / CGFloat(self.items!.count)
tabWidth = self.bounds.width / CGFloat(self.items?.count ?? 4)
let bezPath = drawPath(for: index)

bezPath.close()
fillColor.setFill()
bezPath.fill()
let mask = CAShapeLayer()
mask.fillRule = .evenOdd
mask.fillColor = UIColor.white.cgColor
mask.path = bezPath.cgPath
if (self.animated) {
maskedView.frame = bezPath.bounds
maskLayer.path = bezPath.cgPath
shadowLayer.path = bezPath.cgPath

if (animated) {
let bezAnimation = CABasicAnimation(keyPath: "path")
let bezPathFrom = drawPath(for: previousIndex)
bezAnimation.toValue = bezPath.cgPath
bezAnimation.fromValue = bezPathFrom.cgPath
bezAnimation.duration = 0.3
bezAnimation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
mask.add(bezAnimation, forKey: nil)
maskLayer.add(bezAnimation, forKey: nil)
shadowLayer.add(bezAnimation, forKey: nil)
}
self.layer.mask = mask
}

private func customInit(){
self.tintColor = .white
self.barTintColor = .white
self.backgroundColor = .white
maskedView.center = CGPoint(x: self.frame.size.width / 2,
y: self.frame.size.height / 2)
maskedView.backgroundColor = .white
self.insertSubview(maskedView, at:0)
maskedView.layer.mask = maskLayer

shadowLayer.shadowOpacity = 0.1
shadowLayer.shadowRadius = 2
shadowLayer.shadowColor = UIColor.black.cgColor
shadowLayer.shadowOffset = CGSize(width: 0, height: 0)

maskedView.superview?.layer.insertSublayer(shadowLayer, below: maskedView.layer)

self.tintColor = .clear
self.barTintColor = .clear
}

private func drawPath(for index: CGFloat) -> UIBezierPath {
Expand Down Expand Up @@ -104,6 +115,7 @@ extension SHCircleBar {
bezPath.addCurve(to: rightPoint, controlPoint1: middlePointCurveDown, controlPoint2: middlePointCurveUp)

bezPath.append(UIBezierPath(rect: self.bounds))
bezPath.close()

return bezPath
}
Expand Down
4 changes: 2 additions & 2 deletions CircleBar/Classes/SHCircleBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ extension SHCircleBarController {
circleView.layer.shadowOffset = CGSize(width: 0, height: 0)
circleView.layer.shadowRadius = 2
circleView.layer.shadowColor = UIColor.black.cgColor
circleView.layer.shadowOpacity = 0.15
circleView.layer.shadowOpacity = 0.1

let bottomPadding = getBottomPadding()

circleView.frame = CGRect(
x: tabWidth / 2 - tabWidth*0.25,
x: tabWidth / 2 - circleViewWidth*0.5,
y: self.tabBar.frame.origin.y - bottomPadding - circleViewWidth*0.5,
width: circleViewWidth,
height: circleViewWidth)
Expand Down

0 comments on commit 03ce6cb

Please sign in to comment.