Skip to content

Instantly share code, notes, and snippets.

@hlung
Last active May 7, 2019 04:05
Show Gist options
  • Save hlung/28bf36b590f5525bb4ddd065198a69c9 to your computer and use it in GitHub Desktop.
Save hlung/28bf36b590f5525bb4ddd065198a69c9 to your computer and use it in GitHub Desktop.
import UIKit
import Lottie
protocol LikeSwitchDelegate: class {
func likeSwitch(_ likeSwitch: LikeSwitch, didToggle isSelected: Bool)
}
class LikeSwitch: UIView {
weak var delegate: LikeSwitchDelegate?
private lazy var animatedSwitch: LOTAnimatedSwitch = { // Lottie Animated Switch
let view = LOTAnimatedSwitch(named: "like")
view.isUserInteractionEnabled = false
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private lazy var tapGesture: UITapGestureRecognizer = {
let gesture = UITapGestureRecognizer()
gesture.addTarget(self, action: #selector(userDidToggle))
return gesture
}()
@objc private func userDidToggle() {
let newValue = !animatedSwitch.isOn
delegate?.likeSwitch(self, didToggle: newValue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment