I'm trying to develop an App with an "Around Me"-like feature of a location list with small directional arrows on the side. Bearing and offset to the different locations hadn't been a problem thanks to Stackoverflow and compensating the compass-lag did well with following tutorial: http://www.sundh.com/blog/2011/09/stabalize-compass-of-iphone-with-gyroscope/
All the stuff works fine with only one location in that UITableView. But when there are more than one location, the arrows won't turn smooth and it feels like my iPhone isn't fast enough for calculating the stuff and turning these multiple arrows but I don't know how to do that better.
At the moment I'm trying this (without the locations specific directional offset):
- I'm saving all the UIImageViews of all the cells in an array
when getting a new yaw value I loop through the array an actualize all the Images Rotation
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]; } };
and the setRotateArrow:animated method:
- (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];
}
}
If anyone got an idea how to get the arrows rotation following smoothly the device rotation I would be very thankful.