Skip to content
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
40 changes: 40 additions & 0 deletions AnimatedSwitch.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Be sure to run `pod lib lint AnimatedSwitch.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = 'AnimatedSwitch'
s.version = '0.1.0'
s.summary = 'Swift subclass of the UISwitch which paints over the parent view.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = 'Swift subclass of the UISwitch which paints over the parent view with the color if switch is turned on and returns original superview background color if switch is off.'

s.homepage = 'https://github.com/rockarts/animatedswitch'
s.screenshots = 'https://github.com/alsedi/AnimatedSwitch/raw/master/animation2.gif'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Steven Rockarts' => 'stevenrockarts@gmail.com' }
s.source = { :git => 'https://github.com/rockarts/AnimatedSwitch.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/rockarts'

s.ios.deployment_target = '8.0'

s.source_files = 'AnimatedSwitch/Classes/**/*'

# s.resource_bundles = {
# 'AnimatedSwitch' => ['AnimatedSwitch/Assets/*.png']
# }

# s.public_header_files = 'Pod/Classes/**/*.h'
s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
Empty file added AnimatedSwitch/Assets/.gitkeep
Empty file.
Empty file added AnimatedSwitch/Classes/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@
import UIKit
import QuartzCore

typealias VoidClosure = () -> ()
public typealias VoidClosure = () -> ()

struct AnimatedSwitchConstants {
public struct AnimatedSwitchConstants {
static let animationIdentificator = "animatedSwitch"
static let defaultBorderWidth: CGFloat = 0.5

static let transformKey = "transform"
static let animationLayerKey = "animationLayer"
}

enum AnimatedSwitchShapeType {
public enum AnimatedSwitchShapeType {
case round
case diamond
case star
case custom(UIBezierPath)
}

extension AnimatedSwitchShapeType {
public extension AnimatedSwitchShapeType {

private func polygon(inCircleOfRadius radius: Double, vertices: Int, offset: Double = 0) -> [CGPoint] {
let step = .pi * 2 / Double(vertices)
Expand All @@ -65,8 +65,8 @@ extension AnimatedSwitchShapeType {
if externalVertices.count >= 3 {
path.move(to: externalVertices[0])
for i in 0..<externalVertices.count-1 {
path.addLine(to: internalVertices[i])
path.addLine(to: externalVertices[i + 1])
path.addLine(to: internalVertices[i])
path.addLine(to: externalVertices[i + 1])
}
path.close()
}
Expand Down Expand Up @@ -106,7 +106,7 @@ extension AnimatedSwitchShapeType {
}
}

@IBDesignable class AnimatedSwitch: UISwitch {
@IBDesignable public class AnimatedSwitch: UISwitch {

private var originalParentBackground: UIColor?
private var toColor: UIColor?
Expand All @@ -115,17 +115,17 @@ extension AnimatedSwitchShapeType {

@IBInspectable var color: UIColor = .clear
@IBInspectable var startRadius: Double = 15
@IBInspectable var animationDuration: Double = 0.25
@IBInspectable public var animationDuration: Double = 0.25

@IBInspectable var showBorder: Bool = true
@IBInspectable var borderColor: UIColor = .white

var shape: AnimatedSwitchShapeType = .diamond
public var shape: AnimatedSwitchShapeType = .diamond


var isAnimating: Bool = false
var animationDidStart: VoidClosure?
var animationDidStop: VoidClosure?
public var isAnimating: Bool = false
public var animationDidStart: VoidClosure?
public var animationDidStop: VoidClosure?

private func setupView(_ parent: UIView) {
removeTarget(self, action: #selector(AnimatedSwitch.valueChanged), for: .valueChanged)
Expand All @@ -136,14 +136,14 @@ extension AnimatedSwitchShapeType {
parent.layer.insertSublayer(containerLayer, at: 0)
}

override func willMove(toSuperview newSuperview: UIView?) {
override public func willMove(toSuperview newSuperview: UIView?) {
if let parent = newSuperview {
setupView(parent)
originalParentBackground = parent.backgroundColor
}
}

override func layoutSubviews() {
override public func layoutSubviews() {
guard let parent = superview else { return }
containerLayer.frame = CGRect(x: 0, y: 0, width: parent.frame.width, height: parent.frame.height)
if isOn {
Expand Down Expand Up @@ -202,7 +202,7 @@ extension AnimatedSwitchShapeType {

extension AnimatedSwitch: CAAnimationDelegate {

func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
private func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
CATransaction.begin()
CATransaction.setDisableActions(true)
containerLayer.backgroundColor = toColor?.cgColor
Expand Down
Binary file added Example/.DS_Store
Binary file not shown.
Loading