こんにちは私は地図アプリケーションに取り組んでいます。mapview と imageview を回転させています。annotationView のサブビューです。Mapview の回転は完璧ですが、ImageView は Mapview に従って回転しておらず、常に北方向を指しています。
imageview を回転させるために以下のコードを使用しています:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *identifier = @"annView";
MKPinAnnotationView *annView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
annView=nil;
[annView setSelected:YES animated:NO];
if (annView == nil)
{
annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
}
MyAnnotation *myAnnotation=(MyAnnotation *)annotation;
NSString *details;
if ([myAnnotation isKindOfClass:[MKUserLocation class]])
{
//return nil;
}
else
{
details=[myAnnotation annType];
}
NSLog(@"Details is %@",details);
annView.canShowCallout = YES;
if([details isEqualToString:@"Current"])
{
[[annView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
annView.animatesDrop=NO;
annView.canShowCallout=YES;//pin3.png// Parking_Psymbol//dus2
annView.image=[UIImage imageNamed:@""];
UIImage * locaterImage;
locaterImage = [UIImage imageNamed:@"Locatermap.png"];
locaterImageView = [[UIImageView alloc] initWithImage:locaterImage];
locaterImageView.frame = CGRectMake(-28, -4, 70, 70);
//--------For animating imageview ---------------------
// Setup the animation
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:2.0];
//[UIView setAnimationRepeatCount:10];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
//--------For animating imageview ---------------------
[annView addSubview:locaterImageView];
}
MapView を回転させる場合:
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
// Convert Degree to Radian and move the needle
float oldRad = -manager.heading.trueHeading * M_PI / 180.0f;
float newRad = -newHeading.trueHeading * M_PI / 180.0f;
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
theAnimation.fromValue = [NSNumber numberWithFloat:oldRad];
theAnimation.toValue=[NSNumber numberWithFloat:newRad];
theAnimation.duration = 0.5f;
[mapView.layer addAnimation:theAnimation forKey:@"transform.rotation"];
self.mapView.transform = CGAffineTransformMakeRotation(newRad);
}
私はグーグルで検索しましたが、必要な答えが見つかりません。これを解決するためのアイデアを教えてください。
前もって感謝します。