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

#12 Issue Resolved #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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