以编程方式在iOS7中旋转MKMapView [英] Programmatically rotating a MKMapView in iOS7

查看:195
本文介绍了以编程方式在iOS7中旋转MKMapView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,当前使用CGAffineTransformMakeRotation来操作MKMapView,以便显示具有正确方向和大小的地图。随着iOS7的发布,这种方法变得不可靠(地图中心不断变换)。我希望用更可靠的解决方案来解决这个问题。

I have an app that currently uses CGAffineTransformMakeRotation to manipulate a MKMapView in order to display the map with the correct orientation and size. With the release of iOS7 this method has become unreliable (map center keeps shifting). I am hoping to solve this with a more reliable solution.

有没有办法在不使用CGAffineTransformMakeRotation的情况下在代码中旋转地图?

Is there a way to rotate the map in code without using CGAffineTransformMakeRotation?

我看了MKMapCamera希望我可以操纵它来传递staic值来操纵地图但是没有办法手动设置centerCoordinate和eyeCoordinate。

I looked at the MKMapCamera in hopes I could manipulate it into passing staic values to manipulate the map but there is no way to manually set the centerCoordinate and the eyeCoordinate.

推荐答案

您可以通过使用 -setCamera设置新的 MKMapCamera 来旋转和调整地图:动画:

You can rotate and pitch the map by setting a new MKMapCamera with -setCamera:animated:.

要设置轮换,请为其指定一个新的标题参数:

To set the rotation, give it a new heading parameter:

- (void)viewDidAppear:(BOOL)animated // or wherever works for you
{
    [super viewDidAppear:animated];

    if ([mapView respondsToSelector:@selector(camera)]) {
        MKMapCamera *newCamera = [[mapView camera] copy];
        [newCamera setHeading:90.0]; // or newCamera.heading + 90.0 % 360.0
        [mapView setCamera:newCamera animated:YES];
    }
}

您还可以使用音高进行更精彩的变焦高度变化,显示建筑物:

You can also do a more fancy zoom with pitch and altitude change, showing buildings:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    if ([mapView respondsToSelector:@selector(camera)]) {
        [mapView setShowsBuildings:YES];
        MKMapCamera *newCamera = [[mapView camera] copy];
        [newCamera setPitch:45.0];
        [newCamera setHeading:90.0];
        [newCamera setAltitude:500.0];
        [mapView setCamera:newCamera animated:YES];
    }

}

这篇关于以编程方式在iOS7中旋转MKMapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆