How do I rotate a CALayer 90 degrees? I need to rotate everything include sublayers and the coordinate system.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
- Why is my library not able to expand on the CocoaP
Rab showed how do do it with a
CAAnimation
object. Its actually simpler than that:(lifting the transform line from Chris's answer - too lazy to rewrite it since he already provided the perfect code.)
Chris's code would rotate the view without animation. My code above will do the same thing with animation.
By default, animations use ease in, ease out timing. You can change that with a slightly more complex version of the
animateWithDuration
call (UseanimateWithDuration:delay:options:animations:completion:
instead, and pass in a the desired timing in the options parameter.)Basically something like that:
CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(M_PI / 2.0); [myCALayer setAffineTransform:rotateTransform];
EDIT: It'll rotate clockwise or counter-clockwise depending on the platform (iOS or Mac OS).
Obj-C:
Swift:
That is, transform the layer such that it is rotated by 90 degrees (π / 2 radians), with 100% of that rotation taking place around the z-axis.
To rotate 90' right:
If I'm animating it I use something like this in my apps:
Of course you can use it anywhere, don;t have to return it from a method if that doesn;t suit your needs.