How do I rotate a subview x degrees?

后端 未结 2 1924
盖世英雄少女心
盖世英雄少女心 2021-01-23 16:15

So I want to rotate a subview x degrees (or at least 90 degrees). I want the subwiew to rotate around the subview\'s bottom right corner. Is it possible to do this animated like

相关标签:
2条回答
  • 2021-01-23 16:48

    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 讨论(0)
  • 2021-01-23 17:04
    CGAffineTransform transform = 
        CGAffineTransformMakeRotation(angle);
    
    yourSubView.transform = transform;
    
    0 讨论(0)
提交回复
热议问题