My Connections

Business card

Friday, July 9, 2010

How to rotate compaas needle manually....

#define RadiansTodegrees(Y) ( 180.0* Y / 3.14)

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
theEndPoint = [touch locationInView:self.view];
if((theEndPoint.x>My_Compass.frame.origin.x && theEndPoint.y>My_Compass.frame.origin.y) && (theEndPoint.x {
float Centre_X = My_Compass.frame.origin.x + (My_Compass.frame.size.height/2);
float Centre_Y = My_Compass.frame.origin.y + (My_Compass.frame.size.width/2);

float dx=theEndPoint.x-Centre_X;
float dy=theEndPoint.y-Centre_Y;

double angle=atan2(dy,dx);
double br = RadiansTodegrees(angle);

CGAffineTransform rotate = CGAffineTransformMakeRotation(((br+90)/180)*3.14);
[Niddel setTransform:rotate];

}

}

No comments:

Post a Comment