Pergunta

Well,
i have a circle like this in the photo.
I want to rotate my red line to the degree that i want.

The circle start from 0 to 300 degrees.

I started to do something with

CGFloat wAngle = Degrees2Radians([_Weight.text intValue]/300.0*360);
_Arrow.layer.transform = CATransform3DMakeRotation (wAngle + M_PI, 0, 0, 1);

but in this snippet, 0 value was on top, not on bottom.
Probably because i'm not a genius in trigonometry... :)

enter image description here

What is the correct way to rotate properly the arrow?
How are the values of angle to set?

thanks.

Foi útil?

Solução

You don't need to transform degrees and radians. You have a relative value:

CGFloat relativeAngle = [_Weight.text intValue] / 300.0;

So just use it:

_Arrow.layer.transform = CATransform3DMakeRotation(relativeAngle * M_PI*2, 0, 0, 1);

If the start is wrong just change the initial position of your view. (Or sum up the wrong angle to the new angle. Like (relativeAngle * M_Pi*2 + correction).

// what PI means in degrees
M_PI * 2 = 360°  
M_PI     = 180°  
M_PI_2   = 90°  
M_PI_4   = 45°  

Outras dicas

You can have your relative angle like this

// transform your degrees (0->300) to radians
// (considering your starting direction is at M_PI*3/2)
CGFloat relativeAngle = - [_Weight.text intValue] * M_PI / 150.0;

_Arrow.layer.transform = CATransform3DMakeRotation(relativeAngle, 0, 0, 1);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top