iOS设置MKMapView摄像头标题围绕锚点旋转 [英] iOS set MKMapView camera heading rotation around anchor point

查看:59
本文介绍了iOS设置MKMapView摄像头标题围绕锚点旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MKMapView,我试图围绕它自己的底部中心旋转。我有一个简单的方法,让用户磁力计前进,并将地图的摄像机视图更改为标题,这很好。

I have a MKMapView that I am trying to rotate around the bottom center of itself. I have a simple method that gets the users magnetometer heading and changes the camera view of the map to the heading, this works just fine.

我的问题是设置锚点在地图上以lat / long指向地图将围绕它旋转。我可以使用这种方法将我想要的点设置为我的地图的底部:

My problem though is setting the anchor point on the map in lat/long that the map will rotate around. I can get set my desired point to be the bottom of my map with this method:

-(void)setMapCenterFromLocation:(CLLocationCoordinate2D)location {
    MKCoordinateRegion oldRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(location, 10000, 10000)];
    CLLocationCoordinate2D centerPointOfOldRegion = oldRegion.center;

    CLLocationCoordinate2D centerPointOfNewRegion = CLLocationCoordinate2DMake(centerPointOfOldRegion.latitude + oldRegion.span.latitudeDelta / 2.0, centerPointOfOldRegion.longitude);

    MKCoordinateRegion newRegion = MKCoordinateRegionMake(centerPointOfNewRegion, oldRegion.span);

    [self.mapView setRegion:newRegion animated:YES];
}

我可以旋转地图:

- (void)magneticDirectionChanged:(NSNotification *)notification {
    CLHeading *heading = (CLHeading *)[[notification userInfo] valueForKey:@"heading"];

    CLLocationDirection newDirection = heading.trueHeading;

    self.currentHeading = (int)newDirection;

    [self.mapView.camera setHeading:self.currentHeading];
}

但旋转发生在地图中心周围,而不是底部中心点我想要的。即使我调用setMapCenterFromLocation:在执行旋转之后,它仍然将其视为从北方看,因此它会移到地图的两侧。

But the rotation happens around the center of the map, not the bottom center point that I wanted. Even if I call setMapCenterFromLocation: after doing the rotation, it still counts it as looking from north and thus it goes off to the sides of the map.

如何保持地图底部中心的特定点,同时以编程方式旋转地图/调整地图大小?

How do I keep a specific point on the bottom center of the map while programmatically rotating the map / resizing the map?

编辑:我认为解决方案是将地图的高度加倍然后隐藏地图的下半部分,使其不可见。如何实现?

A solution I suppose would be to double the height of the map and then hide the bottom half of the map from being visible. How could this be accomplished?

推荐答案

首先,在Interface Builder中,将地图视图粘贴在滚动视图中。然后将地图视图上的高度设置为1000.地图视图的中心将位于屏幕的底部。这适用于视图控制器上的零自动布局约束。

First, in Interface Builder, stick the map view in a scroll view. Then set the height on the map view to something like 1000. The center of the map view will be on the bottom of the screen. This worked with zero auto layout constraints on the view controller.

对我来说,关键是滚动视图部分。直到我添加它,我无法获得高于568的地图视图(尽管更大的宽度工作),无论我在IB中设置它。我想滚动视图会强制超出限制高度的任何内容。

The key for me was the scroll view part. Up until I added it, I couldn't get the map view to draw any higher than 568 (although larger widths worked), no matter what I set it to in IB. I guess the scroll view forces past whatever is restricting the height.

这篇关于iOS设置MKMapView摄像头标题围绕锚点旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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