2012-12-06 50 views
0

您好我正在處理地圖應用程序。我正在旋轉mapview和imageview,它是annotationView的子視圖。 Mapview旋轉是完美的,但imageview不是根據Mapview旋轉,並始終指向北方向。在地圖上的自定義ImageView不與地圖視圖一起旋轉iphone

我使用下面的代碼用於旋轉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); 
} 

我GOOGLE了,但我不能找到我需要的答案。請給出任何想法來解決這個問題。

在此先感謝。

回答

0

這一切只是爲了旋轉地圖,以匹配現實世界?即北方的地圖真的指向北方嗎?如果是這樣,你需要做的是將MKMapViewuserTrackingMode設置爲MKUserTrackingModeFollowWithHeading

+0

我沒有清楚地告訴你 –

+0

爲什麼你要旋轉地圖?你想讓地圖轉向,以便地圖上的北方指向北極嗎? – Craig