开发者

How do I rotate a subview x degrees?

开发者 https://www.devze.com 2023-02-03 20:04 出处:网络
So I want to rotate a subview x degrees (or at least 90 degrees). I wan开发者_高级运维t the subwiew to rotate around the subview\'s bottom right corner. Is it possible to do this animated like in the

So I want to rotate a subview x degrees (or at least 90 degrees). I wan开发者_高级运维t the subwiew to rotate around the subview's bottom right corner. Is it possible to do this animated like in the picture below?

How do I rotate a subview x degrees?

Thanks!


CGAffineTransform transform = 
    CGAffineTransformMakeRotation(angle);

yourSubView.transform = transform;


Yo can do it composing transforms. First translate to the rotation origin, then rotate, then transform back to the original center. The view you are rotating is v. It is inside an animation just for fun.

[UIView beginAnimations:nil context:NULL];
CGAffineTransform t = CGAffineTransformIdentity;
t =CGAffineTransformTranslate(t,- v.bounds.size.width/2,  -v.bounds.size.height/2);
t =  CGAffineTransformRotate(t, -M_PI/2);
t =CGAffineTransformTranslate(t,v.bounds.size.width/2, v.bounds.size.height/2);
v.transform = t;
[UIView commitAnimations];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号