OGeek|极客世界-中国程序员成长平台

标题: ios - 在 2D 和 3D map View 之间切换 (pitchEnabled) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:14
标题: ios - 在 2D 和 3D map View 之间切换 (pitchEnabled)

我有一个 iOs map 应用程序,其中默认使用 3D View 。因此,MKMapCamera 设置在开头(音高值为45)。但是,我想为用户提供禁用 3D map 的选项,以防他们更喜欢 2D map 。因此,为了在 View 之间进行切换,我将更改相机的俯仰角(0 在 2D 中,45 在 3D 中)并禁用/启用更改它( setPitchEnabled = NO/YES).

由于某种原因,在我禁用了音高之后,我无法再启用 3D View ,即在我设置了一次 [_mapView setPitchEnabled:NO] 之后,我无法更改将其更改为 YES (尝试将其更改回 YES 后,pitchEnabled 将其值保持为 NO 时它打印在 NSLog 中)。 因此我无法从 2D 回到 3D。您知道是什么原因造成的吗?这很令人困惑,因为我尝试启用和禁用旋转([_mapView setRotationEnabled:NO]YES) 以相同的方式,在这种情况下,它在这两种情况下完美地工作。但不是与音高 - 在禁用音高后,我无法再启用它。下面是开始设置相机的函数(setCamera)和在模式之间切换的函数(toggleViewMode)。

//Function that sets the 3D-view in the beginning

-(void)setCamera {

    CLLocationCoordinate2D userLocation;
    userLocation.latitude = self.locationManager.currentLatitude;
    userLocation.longitude = self.locationManager.currentLongitude;

    if(_cameraSet == YES) {
        NSLog(@"Camera is set already, return");
        return;
    }


    if ([_mapView respondsToSelectorselector(camera)] && _show3Dmap) {

        _cameraSet = YES;
        [_mapView setShowsBuildings:NO];

        MKMapCamera *newCamera = [[_mapView camera] copy];
        [newCamera setPitch:45.0];
        [newCamera setHeading:0.0];
        [newCamera setAltitude:500.0];

        [_mapView setCamera:newCamera animated:NO];
    } 
}


//Toggle between 2D and 3D
-(void)toggleViewModeBOOL)birdView {

    if(birdView == YES) {
        _mapView.camera.pitch = 45;
        [_mapView setPitchEnabled:YES];
    } else {
        _mapView.camera.pitch = 0;
        [_mapView setPitchEnabled:NO];
    }

}

}



Best Answer-推荐答案


在别处找到答案。 您还必须设置相机。

这是一个示例相机初始化:

MKMapCamera *newCamera = [[self.mapView camera] copy];
[newCamera setPitch:45.0];
[newCamera setHeading:90.0];
[newCamera setAltitude:500.0];
[self.mapView setCamera:newCamera animated:YES];

关于ios - 在 2D 和 3D map View 之间切换 (pitchEnabled),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22915949/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4