我正在尝试对 MKMapView
应用透视变换。我以 this Stackoverflow question 为例,所以我的代码看起来像这样(插入到 View Controller 的 viewDidLoad
方法中):
MKMapView *map = [[MKMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
[self.view addSubview:map];
CLLocationDistance distance = 2000000.0;
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(52.5, 13.4);
[map setRegion:MKCoordinateRegionMakeWithDistance(coordinate, distance, distance)];
CATransform3D transform = CATransform3DIdentity;
transform.m34 = 1.0 / -1200.0;
transform = CATransform3DRotate(transform, M_PI_4, 1.0, 0.0, 0.0);
map.layer.transform = transform;
这段代码,正如所写的那样,运行良好,我得到了一张应用了透视图的欧洲 map 。问题是,如果我减少 distance
变量以获得更近的 View ,或者甚至从这个工作初始状态放大, map 不会正确放大,它只是按原样缩放 map 缩小状态。另一方面,如果我不设置 transform
的 m34
字段,即只倾斜 map 而没有透视,它工作得很好。
有没有办法获得带有透视图的街道 map ?
最佳答案
我设法通过添加来使透视工作正常
[map.layer setShouldRasterize:YES];
显然,在应用透视图时直接渲染 map 内容存在问题。
关于ios5 - 对 MKMapView 应用透视变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9161411/