2011-09-27 51 views
0

我有一个指南针/图像,指针应始终指向北方。iPhone - 如何旋转指南针北磁头

我有罗盘针/转盘使用以下条件语句旋转:

double heading = newHeading.magneticHeading; 

    if(heading >= 0.0 && heading <= 23.0) { 

      needleView.transform=CGAffineTransformMakeRotation(heading); 

      NSLog(@"N"); 
      currentDirLabel.text = @"N"; 

     } 

我想知道是否有人知道我怎么会去旋转needleView始终指向北。

下面是我使用旋转needleView的UIView代码:

- (void)rotateImage:(UIImageView *)image duration:(NSTimeInterval)duration 
       curve:(int)curve degrees:(CGFloat)degrees 
{ 
    // Setup the animation 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:duration]; 
    [UIView setAnimationCurve:curve]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 

    // The transform matrix 
    CGAffineTransform transform = 
    CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees)); 
    image.transform = transform; 

    // Commit the changes 
    [UIView commitAnimations]; 
} 

澄清:UIView的(needleView)正在旋转的magneticHeading变化。我期待着始终锁定在北方方向的图像(在这种情况下,与北针图像的一部分)

感谢您的任何帮助。

回答

-1

本书:Oreilly.Basic.Sensors.in.iOS.Jul.2011帮助我解决了这个问题。

+0

这是一个广告,而不是一个答案。 – Nathan