diff --git a/README.md b/README.md index 910a28d..50f813b 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,11 @@ view.addSubview(bt1) [ShineButton](https://github.com/ChadCSong/ShineButton) +## Third Party Bindings + +### React Native +You may now use this library with [React Native](https://github.com/facebook/react-native) via the module [here](https://github.com/prscX/react-native-shine-button) + ## **License** WCLShineButton is released under the [MIT license](https://github.com/631106979/WCLShineButton/blob/master/LICENSE). See LICENSE for details. diff --git a/WCLShineButton.podspec b/WCLShineButton.podspec index 3b33f9f..cf908b1 100644 --- a/WCLShineButton.podspec +++ b/WCLShineButton.podspec @@ -20,5 +20,5 @@ Pod::Spec.new do |s| s.resources = 'WCLShineButton/WCLShineButton.bundle' s.frameworks = "UIKit" s.requires_arc = true - + s.swift_version = '4.2' end diff --git a/WCLShineButton/WCLShineAngleLayer.swift b/WCLShineButton/WCLShineAngleLayer.swift index 7717364..7436edb 100644 --- a/WCLShineButton/WCLShineAngleLayer.swift +++ b/WCLShineButton/WCLShineAngleLayer.swift @@ -76,7 +76,7 @@ class WCLShineAngleLayer: CALayer, CAAnimationDelegate { } let angleAnim = CABasicAnimation(keyPath: "transform.rotation") angleAnim.duration = params.animDuration * 0.87 - angleAnim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) + angleAnim.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear) angleAnim.fromValue = 0 angleAnim.toValue = CGFloat(params.shineTurnAngle)*CGFloat(Double.pi)/180 angleAnim.delegate = self @@ -94,7 +94,7 @@ class WCLShineAngleLayer: CALayer, CAAnimationDelegate { }else { displaylink?.frameInterval = 6 } - displaylink?.add(to: .current, forMode: .commonModes) + displaylink?.add(to: .current, forMode: RunLoop.Mode.common) } private func addShines() { @@ -145,9 +145,9 @@ class WCLShineAngleLayer: CALayer, CAAnimationDelegate { let center = getShineCenter(angle: angle, radius: radius) let path = UIBezierPath(arcCenter: center, radius: 0.1, startAngle: 0, endAngle: CGFloat(Double.pi)*2, clockwise: false) anim.toValue = path.cgPath - anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) + anim.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut) anim.isRemovedOnCompletion = false - anim.fillMode = kCAFillModeForwards + anim.fillMode = CAMediaTimingFillMode.forwards return anim } @@ -160,7 +160,7 @@ class WCLShineAngleLayer: CALayer, CAAnimationDelegate { flash.repeatCount = MAXFLOAT flash.isRemovedOnCompletion = false flash.autoreverses = true - flash.fillMode = kCAFillModeForwards + flash.fillMode = CAMediaTimingFillMode.forwards return flash } diff --git a/WCLShineButton/WCLShineButton.swift b/WCLShineButton/WCLShineButton.swift index 9039daa..a577340 100644 --- a/WCLShineButton/WCLShineButton.swift +++ b/WCLShineButton/WCLShineButton.swift @@ -52,9 +52,28 @@ public class WCLShineButton: UIControl { } /// button的图片 - public var image: WCLShineImage = .heart { + @IBInspectable public var image: NSString = ".heart" { willSet { - clickLayer.image = newValue + switch newValue { + case ".heart": + clickLayer.image = .heart + case ".like": + clickLayer.image = .like + case ".smile": + clickLayer.image = .smile + case ".star": + clickLayer.image = .star + default: + clickLayer.image = .heart + } +// clickLayer.image = newValue + } + } + + @objc public var customImage: UIImage = UIImage() { + willSet { + let image = WCLShineImage.custom(newValue) + clickLayer.image = image } } @@ -64,6 +83,11 @@ public class WCLShineButton: UIControl { clickLayer.clicked = isSelected } } + + @IBInspectable public var getSelection: Bool { + print("Clicked: \(clickLayer.clicked)") + return clickLayer.clicked + } private var clickLayer = WCLShineClickLayer() @@ -89,6 +113,7 @@ public class WCLShineButton: UIControl { initLayers() } + @objc public func setClicked(_ clicked: Bool, animated: Bool = true) { guard clicked != clickLayer.clicked else { return @@ -117,11 +142,12 @@ public class WCLShineButton: UIControl { super.touchesEnded(touches, with: event) if clickLayer.clicked == false { shineLayer.endAnim = { [weak self] in - self?.clickLayer.clicked = !(self?.clickLayer.clicked ?? false) +// self?.clickLayer.clicked = !(self?.clickLayer.clicked ?? false) self?.clickLayer.startAnim() - self?.isSelected = self?.clickLayer.clicked ?? false +// self?.isSelected = self?.clickLayer.clicked ?? false self?.sendActions(for: .valueChanged) } + clickLayer.clicked = true shineLayer.startAnim() }else { clickLayer.clicked = !clickLayer.clicked @@ -131,7 +157,8 @@ public class WCLShineButton: UIControl { } //MARK: Privater Methods - private func initLayers() { + @objc + public func initLayers() { clickLayer.animDuration = params.animDuration/3 shineLayer.params = params clickLayer.frame = bounds @@ -140,3 +167,4 @@ public class WCLShineButton: UIControl { layer.addSublayer(shineLayer) } } + diff --git a/WCLShineButton/WCLShineClickLayer.swift b/WCLShineButton/WCLShineClickLayer.swift index 984dbcd..2354fc9 100644 --- a/WCLShineButton/WCLShineClickLayer.swift +++ b/WCLShineButton/WCLShineClickLayer.swift @@ -71,7 +71,7 @@ class WCLShineClickLayer: CALayer { let anim = CAKeyframeAnimation(keyPath: "transform.scale") anim.duration = animDuration anim.values = [0.4, 1, 0.9, 1] - anim.calculationMode = kCAAnimationCubic + anim.calculationMode = CAAnimationCalculationMode.cubic if image.isDefaultAndSelect() { add(anim, forKey: "scale") }else { diff --git a/WCLShineButton/WCLShineLayer.swift b/WCLShineButton/WCLShineLayer.swift index 94327ba..1584635 100644 --- a/WCLShineButton/WCLShineLayer.swift +++ b/WCLShineButton/WCLShineLayer.swift @@ -50,9 +50,9 @@ class WCLShineLayer: CALayer, CAAnimationDelegate { let toPath = UIBezierPath(arcCenter: CGPoint.init(x: size.width/2, y: size.height/2), radius: size.width/2 * CGFloat(params.shineDistanceMultiple), startAngle: 0, endAngle: CGFloat(Double.pi) * 2.0, clockwise: false).cgPath anim.delegate = self anim.values = [fromPath, toPath] - anim.timingFunctions = [CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)] + anim.timingFunctions = [CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeOut)] anim.isRemovedOnCompletion = false - anim.fillMode = kCAFillModeForwards + anim.fillMode = CAMediaTimingFillMode.forwards shapeLayer.add(anim, forKey: "path") if params.enableFlashing { startFlash() @@ -90,7 +90,7 @@ class WCLShineLayer: CALayer, CAAnimationDelegate { }else { displaylink?.frameInterval = 10 } - displaylink?.add(to: .current, forMode: .commonModes) + displaylink?.add(to: .current, forMode: RunLoop.Mode.common) } @objc private func flashAction() {