Last active
March 4, 2025 11:23
-
-
Save brocoo/47e06b5b34602c67b3bb to your computer and use it in GitHub Desktop.
Flip UIView around any axis
This file contains 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
extension CGFloat { | |
var toRadians: CGFloat { | |
return self * CGFloat(M_PI) / 180.0 | |
} | |
var toDegress: CGFloat { | |
return self * 180 / CGFloat(M_PI) | |
} | |
} | |
public enum Axis { | |
case X | |
case Y | |
case Z | |
} | |
extension UIView { | |
func flip(aroundAxis axis: Axis, byDegrees degrees: CGFloat) { | |
let coordinates: (x: CGFloat, y: CGFloat, z: CGFloat) = { | |
switch axis { | |
case .X: return (1, 0, 0) | |
case .Y: return (0, 1, 0) | |
case .Z: return (0, 0, 1) | |
} | |
}() | |
self.layer.transform = CATransform3DMakeRotation(degrees.toRadians, coordinates.x, coordinates.y, coordinates.z) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment