我使用CGAffineTransformMakeRotation来旋转标签,为什么只有文字旋转?

时间:2014-02-16 07:09:23

标签: ios objective-c rotation uilabel

我的代码就是这样:

[label2 setTransform:CGAffineTransformMakeRotation(-M_PI / 2)];

旋转之前,请按照

enter image description here

像那样旋转

enter image description here

任何人都可以告诉我原因,谢谢?

1 个答案:

答案 0 :(得分:0)

你可以这样做:

-(NSPoint)rotatePoint:(NSPoint)inPt
          aroundPoint:(NSPoint)center
            withAngle:(double)radians
{
    NSPoint temp = {inPt.x - center.x, inPt.y - center.y};
    double sinAngle = sin(radians);
    double cosAngle = cos(radians);
    NSPoint result;
    result.x = temp.x * cosAngle - temp.y * sinAngle;
    result.y = temp.x * sinAngle + temp.y * cosAngle;

    result.x += center.x;
    result.y += center.y;
}

然后为您正在旋转的视图框架的4个角调用上述方法,并将框架设置为新值。