AnimatableBarButtonItem.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // Created by Jake Lin on 12/16/15.
  3. // Copyright © 2015 IBAnimatable. All rights reserved.
  4. //
  5. import UIKit
  6. @IBDesignable
  7. open class AnimatableBarButtonItem: UIBarButtonItem, BarButtonItemDesignable, Animatable {
  8. // MARK: - BarButtonItemDesignable
  9. @IBInspectable open var roundedImage: UIImage?
  10. // MARK: - Lifecycle
  11. open override func prepareForInterfaceBuilder() {
  12. super.prepareForInterfaceBuilder()
  13. configureInspectableProperties()
  14. }
  15. open override func awakeFromNib() {
  16. super.awakeFromNib()
  17. configureInspectableProperties()
  18. }
  19. // TODO: animations
  20. // public override func layoutSubviews() {
  21. // super.layoutSubviews()
  22. //
  23. // autoRunAnimation()
  24. // }
  25. // MARK: - Animatable
  26. open var animationType: AnimationType = .none
  27. @IBInspectable var _animationType: String? {
  28. didSet {
  29. animationType = AnimationType(string: _animationType)
  30. }
  31. }
  32. @IBInspectable open var autoRun: Bool = true
  33. @IBInspectable open var duration: Double = Double.nan
  34. @IBInspectable open var delay: Double = Double.nan
  35. @IBInspectable open var damping: CGFloat = CGFloat.nan
  36. @IBInspectable open var velocity: CGFloat = CGFloat.nan
  37. @IBInspectable open var force: CGFloat = CGFloat.nan
  38. @IBInspectable var _timingFunction: String = "" {
  39. didSet {
  40. timingFunction = TimingFunctionType(string: _timingFunction)
  41. }
  42. }
  43. open var timingFunction: TimingFunctionType = .none
  44. // MARK: - Private
  45. fileprivate func configureInspectableProperties() {
  46. configureBarButtonItemImage()
  47. }
  48. }