How to programmatically rotate the view by 180 degrees on iOS?

后端 未结 7 1058
面向向阳花
面向向阳花 2021-02-04 10:15

How to programmatically rotate the view by 180 degrees in my iPhone App?

7条回答
  •  孤街浪徒
    2021-02-04 11:05

    Should be possible by using CGAffineTransform

    Quote from this question, this should do the trick:

    CGFloat radians = atan2f(yourView.transform.b, yourView.transform.a);
    CGFloat degrees = radians * (180 / M_PI);
    CGAffineTransform transform = CGAffineTransformMakeRotation((90 + degrees) * M_PI/180);
    yourView.transform = transform;
    

提交回复
热议问题