【问题标题】:Custom ImageView on the map is not rotating along with MapView in iphone地图上的自定义 ImageView 不与 iPhone 中的 MapView 一起旋转
【发布时间】:2012-12-07 11:08:26
【问题描述】:

您好,我正在开发地图应用程序。我正在旋转 mapview 和 imageview,它是 annotationView 上的子视图。 Mapview旋转是完美的,但是imageview并没有按照Mapview旋转,总是指向北方。

我正在使用以下代码来旋转图像视图:

-(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);
}

我用谷歌搜索,但找不到我需要的答案。请给出解决此问题的任何想法。

提前致谢。

【问题讨论】:

    标签: ios uiimageview ios6 mkmapview


    【解决方案1】:

    这一切只是为了让地图与现实世界相匹配吗? IE。地图上的北方真的是指北吗?如果是这样,您需要做的是将MKMapViewuserTrackingMode 设置为MKUserTrackingModeFollowWithHeading

    【讨论】:

    • 为什么要旋转地图?你想让地图转向,使地图上的北方指向北极吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多