For an application I have to create a menu which consists of an arrow and circles to which the arrow has to point.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if (location.y >= lastLocation.y)
{
float dx = location.x - lastLocation.x;
float dy = location.y - lastLocation.y;
float angleToRotate = 0 - atanf(dx/dy) + M_PI;
CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(angleToRotate);
arrow.transform = cgaRotate;
}
if (location.y < lastLocation.y)
{
float dx = location.x - lastLocation.x;
float dy = location.y - lastLocation.y;
float angleToRotate = 0 - atanf(dx/dy);
CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(angleToRotate);
arrow.transform = cgaRotate;
}
}
At the moment this is my code to handle the arrow rotation. The only problem I have is that it doesn't follow fast enough. I also want the arrow to point at the final location of my touch on touchesEnded.
There's probably something wrong with the two if's. But I don't know how else I would find out the angle of rotation.
When the application starts up, the arrow points to the right. I don't know if that helps with finding a solution but you never know right :)
I hope someone understands what I want to do and can help me out with this. Math is a long time ago.
Thanks in advance,
Lewion