围绕预定轴旋转图像

时间:2011-08-03 15:44:48

标签: objective-c image xcode4

我的应用程序中有一个米的视图。根据我传递给它的一组布线,仪表有一个旋转到目前为止的针。问题是我只是让针正确旋转而遇到很多麻烦。

needle.layer.anchorPoint = CGPointMake(0.85, 0.5); // Set point of rotation

if(isHelpful == true)
{
    // rotate only a little
    needle.transform = CGAffineTransformMakeRotation(7*M_PI/180);
}

if(isNeeded == true)
{
    // rotate 95 degrees
    needle.transform = CGAffineTransformMakeRotation(95*M_PI/180);
}

if(isCritical == true)
{
    // rotate 175 degrees
    needle.transform = CGAffineTransformMakeRotation(175*M_PI/180);
}

这使得针可以完美地旋转,但是由于某种原因它也会改变它的位置,在我的笔尖上移动。我需要将图像保留在笔尖上的相同位置,并围绕特定轴旋转到我确定的程度。

图像为145x36,轴点为127x18。

1 个答案:

答案 0 :(得分:0)

更改视图图层的anchorPoint会影响位置。 Brad Larson对this question的答案有很好的解释。

相关问题