开发者

iPhone - How to rotate compass for North magneticHeading

I have a compass/image where the needle should always point North.

I have the compass needle/dial rotating using the following conditional statement:

  double heading = newHeading.magneticHeading;

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

            needleView.transform=CGAffineTransformMakeRotation(heading); 

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

        }

I was wondering if anyone knew how I'd go about rotating the needleView to always point North.开发者_高级运维

Here's the code I'm using to rotate the 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];
}

To clarify: the UIView (needleView) is spinning as the magneticHeading changes. I'm looking to always lock the the image in the Northerly direction (in this case the part of the image with the North needle)

thanks for any help.


this book: Oreilly.Basic.Sensors.in.iOS.Jul.2011 helped me solved this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜