movemt,.
This commit is contained in:
parent
dd47707064
commit
83370956c1
@ -9,8 +9,6 @@
|
|||||||
import MVMCore
|
import MVMCore
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public typealias ValueChangeBlock = () -> ()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A custom implementation of Apple's UISwitch.
|
A custom implementation of Apple's UISwitch.
|
||||||
|
|
||||||
@ -27,11 +25,11 @@ public typealias ValueChangeBlock = () -> ()
|
|||||||
public var disabledTintColor: (track: UIColor?, thumb: UIColor?)? = (track: .mfSilver(), thumb: .white)
|
public var disabledTintColor: (track: UIColor?, thumb: UIColor?)? = (track: .mfSilver(), thumb: .white)
|
||||||
|
|
||||||
private var valueShouldChange = false
|
private var valueShouldChange = false
|
||||||
private var canChangeValue = false
|
// private var canChangeValue = false
|
||||||
private var shouldTouchToSwitch = false
|
private var shouldTouchToSwitch = false
|
||||||
|
|
||||||
private var valueChangedBlock: ValueChangeBlock?
|
private var valueChangedBlock: ActionBlock?
|
||||||
private var actionBlock: ValueChangeBlock?
|
private var actionBlock: ActionBlock?
|
||||||
|
|
||||||
// Sizes are from InVision design specs.
|
// Sizes are from InVision design specs.
|
||||||
static let trackSize = CGSize(width: 46, height: 24)
|
static let trackSize = CGSize(width: 46, height: 24)
|
||||||
@ -90,13 +88,13 @@ public typealias ValueChangeBlock = () -> ()
|
|||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init(isOn: Bool, changeBlock: ValueChangeBlock?) {
|
public convenience init(isOn: Bool, changeBlock: ActionBlock?) {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
self.isOn = isOn
|
self.isOn = isOn
|
||||||
valueChangedBlock = changeBlock
|
valueChangedBlock = changeBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
public convenience init(changeBlock: ValueChangeBlock?) {
|
public convenience init(changeBlock: ActionBlock?) {
|
||||||
self.init(frame: .zero)
|
self.init(frame: .zero)
|
||||||
valueChangedBlock = changeBlock
|
valueChangedBlock = changeBlock
|
||||||
}
|
}
|
||||||
@ -116,19 +114,19 @@ public typealias ValueChangeBlock = () -> ()
|
|||||||
heightConstraint?.constant = Switch.getTrackHeight()
|
heightConstraint?.constant = Switch.getTrackHeight()
|
||||||
widthConstraint?.constant = Switch.getTrackWidth()
|
widthConstraint?.constant = Switch.getTrackWidth()
|
||||||
|
|
||||||
layer.cornerRadius = Switch.getTrackHeight() / 2.0
|
|
||||||
thumbView.layer.cornerRadius = Switch.getThumbHeight() / 2.0
|
|
||||||
|
|
||||||
thumbHeightConstraint?.constant = Switch.getThumbHeight()
|
thumbHeightConstraint?.constant = Switch.getThumbHeight()
|
||||||
thumbWidthConstraint?.constant = Switch.getThumbWidth()
|
thumbWidthConstraint?.constant = Switch.getThumbWidth()
|
||||||
|
|
||||||
|
layer.cornerRadius = Switch.getTrackHeight() / 2.0
|
||||||
|
thumbView.layer.cornerRadius = Switch.getThumbHeight() / 2.0
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func setupView() {
|
public override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
guard !subviews.isEmpty else { return }
|
guard subviews.isEmpty else { return }
|
||||||
|
|
||||||
canChangeValue = true
|
// canChangeValue = true
|
||||||
shouldTouchToSwitch = true
|
shouldTouchToSwitch = true
|
||||||
valueShouldChange = true
|
valueShouldChange = true
|
||||||
|
|
||||||
@ -263,11 +261,6 @@ public typealias ValueChangeBlock = () -> ()
|
|||||||
valueShouldChange = true
|
valueShouldChange = true
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
|
||||||
|
|
||||||
sendActions(for: .touchUpInside)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
|
public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
|
||||||
|
|
||||||
if shouldTouchToSwitch {
|
if shouldTouchToSwitch {
|
||||||
@ -304,14 +297,13 @@ public typealias ValueChangeBlock = () -> ()
|
|||||||
|
|
||||||
if shouldTouchToSwitch {
|
if shouldTouchToSwitch {
|
||||||
thumbReformAnimation(true)
|
thumbReformAnimation(true)
|
||||||
canChangeValue = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendActions(for: .touchCancel)
|
sendActions(for: .touchCancel)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Animation
|
// MARK: - Animations
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func thumbEnlargeAnimation() {
|
public func thumbEnlargeAnimation() {
|
||||||
@ -443,10 +435,10 @@ extension Switch {
|
|||||||
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
|
||||||
guard let dictionary = json else { return }
|
|
||||||
|
|
||||||
FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
|
FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
|
||||||
|
|
||||||
|
guard let dictionary = json else { return }
|
||||||
|
|
||||||
if let color = dictionary["onTintColor"] as? String {
|
if let color = dictionary["onTintColor"] as? String {
|
||||||
trackTintColor?.on = UIColor.mfGet(forHex: color)
|
trackTintColor?.on = UIColor.mfGet(forHex: color)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user