2013-03-06 73 views
0

在我的應用程序中,我使用了SMRotatory輪進行旋轉。它作爲輪換正常工作。檢查iPhone中的旋轉SDk

但我想檢測到,旋轉是順時針還是逆時針?

//My code is as follow: 

- (BOOL)continueTrackingWithTouch:(UITouch*)touch withEvent:(UIEvent*)event 
{ 

    CGFloat radians = atan2f(container.transform.b, container.transform.a); 
    // NSLog(@"rad is %f", radians); 
    CGPoint pt = [touch locationInView:self]; 

    float dx = pt.x - container.center.x; 
    float dy = pt.y - container.center.y; 
    float ang = atan2(dy,dx); 
    float angleDifference = deltaAngle - ang; 
    // NSLog(@"%f",angleDifference); 



    if (angleDifference>=0) { 
     //NSLog(@"positive"); 
     [[NSUserDefaults standardUserDefaults]setValue:@"positive" forKey:@"CheckValue"]; 
    } 
    else 
    { 
     // NSLog(@"negative"); 
     [[NSUserDefaults standardUserDefaults]setValue:@"negative" forKey:@"CheckValue"]; 
    } 

    container.transform = CGAffineTransformRotate(startTransform, -angleDifference); 

    bg.transform=CGAffineTransformRotate(startTransform, -angleDifference); 

    return YES; 
} 

回答

0

嘗試這樣:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

    UITouch *touch = [touches anyObject]; 
    CGPoint currentTouch1=[touch locationInView:self.superview]; 
    CGPoint currentTouch2=[touch previousLocationInView:self.superview]; 

    CGFloat x = currentTouch2.x - currentTouch1.x; 
    CGFloat y = currentTouch2.y - currentTouch1.y; 
    CGFloat dist = sqrtf(x*x + y*y); 
    CGFloat cx = currentTouch1.x - self.superview.bounds.size.width/2; 
    CGFloat cy = currentTouch2.y - self.superview.bounds.size.height/2; 
    CGFloat cdist = sqrtf(cx*cx + cy*cy); 
    CGFloat angle = atan2(dist, cdist); 
    //NSLog(@"%f",angle); 

    CGFloat radians = atan2f(super.transform.b, super.transform.a); 
    mDegrees = radians * (180/M_PI); 
    if (mDegrees < 0.0) 
    { 
     mDegrees+=360; 
    } 

    NSLog(@"Angle is = %f",angle); //positive is clockwise, negative is counterclockwise 

    CGAffineTransform transform = CGAffineTransformRotate(self.transform, angle); 
    self.transform = transform; 
    touch1 = currentTouch1; 
    touch2 = currentTouch2; 
}