Last active
May 7, 2019 04:05
-
-
Save hlung/28bf36b590f5525bb4ddd065198a69c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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