RotationDesignable.swift 640 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // Created by Jake Lin on 12/5/15.
  3. // Copyright © 2015 IBAnimatable. All rights reserved.
  4. //
  5. import UIKit
  6. import Darwin
  7. /**
  8. It is not able to preview the rotation in IB.
  9. */
  10. public protocol RotationDesignable: class {
  11. var rotate: CGFloat { get set }
  12. }
  13. // MARK: - UIView
  14. extension RotationDesignable where Self: UIView {
  15. public func configureRotate() {
  16. configureRotate(in: self)
  17. }
  18. }
  19. // MARK: - Common
  20. extension RotationDesignable {
  21. func configureRotate(in view: UIView) {
  22. if !rotate.isNaN && rotate > -360 && rotate < 360 {
  23. view.transform = CGAffineTransform(rotationAngle: .pi * rotate / 180)
  24. }
  25. }
  26. }