我正在尝试开发一个具有“我周围”类似功能的应用程序,其中包含侧面有小方向箭头的位置列表。 Stackoverflow支持和偏移到不同的位置并不是问题,并且补偿罗盘延迟在以下教程中做得很好: http://www.sundh.com/blog/2011/09/stabalize-compass-of-iphone-with-gyroscope/
只有UITableView中的一个位置,所有东西都能正常工作。 但是当有多个位置时,箭头将不会变得平滑,感觉就像我的iPhone不够快,无法计算这些东西并转动这些多个箭头,但我不知道如何做得更好。
目前我正在尝试这个(没有位置特定的方向偏移):
当获得新的偏航值时,我循环遍历数组,实现所有图像旋转
if(motionManager.isDeviceMotionAvailable) {
// Listen to events from the motionManager
motionHandler = ^ (CMDeviceMotion *motion, NSError *error) {
CMAttitude *currentAttitude = motion.attitude;
float yawValue = currentAttitude.yaw; // Use the yaw value
// Yaw values are in radians (-180 - 180), here we convert to degrees
float yawDegrees = CC_RADIANS_TO_DEGREES(yawValue);
currentYaw = yawDegrees;
// We add new compass value together with new yaw value
yawDegrees = newCompassTarget + (yawDegrees - offsetG);
// Degrees should always be positive
if(yawDegrees < 0) {
yawDegrees = yawDegrees + 360;
}
compassDif.text = [NSString stringWithFormat:@"Gyro: %f",yawDegrees]; // Debug
float gyroDegrees = (yawDegrees*radianConst);
// If there is a new compass value the gyro graphic animates to this position
if(updateCompass) {
[self setRotateArrow:gyroDegrees animated:YES];
[self commitAnimations];
updateCompass = 0;
} else {
[self setRotateArrow:gyroDegrees animated:NO];
[UIView commitAnimations];
}
};
和setRotateArrow:动画方法:
- (void) setRotateArrow:(float)degrees animated:(BOOL)animated{
UIImage *arrowImage = [UIImage imageNamed:@"DirectionArrow.png"];
for (int i = 0; i<arrowImageViews.count; i++) {
[(UIImageView *)[arrowImageViews objectAtIndex:i] setImage:arrowImage];
CGFloat arrowTransform = degrees;
//Rotate the Arrow
CGAffineTransform rotate = CGAffineTransformMakeRotation(arrowTransform);
[(UIImageView *)[arrowImageViews objectAtIndex:i] setTransform:rotate];
}
}
如果有人知道如何让箭头旋转顺利进行设备旋转,我将非常感激。