【问题标题】:iPhone - How to rotate compass for North magneticHeadingiPhone - 如何为北磁航向旋转指南针
【发布时间】:2011-09-27 07:01:22
【问题描述】:

我有一个指南针/图像,指针应始终指向北方。

我使用以下条件语句让罗盘指针/刻度盘旋转:

  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)随着磁头变化而旋转。我希望始终将图像锁定在北方向(在这种情况下,图像中带有北针的部分)

感谢您的帮助。

【问题讨论】:

    标签: iphone objective-c ios core-location


    【解决方案1】:

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

    【讨论】:

    • 这是广告,不是答案。
    猜你喜欢
    • 2011-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    相关资源
    最近更新 更多