gkl*_*lka 9 objective-c mkmapview
UIScrollView有一个很好的contentInset属性,告诉视图,哪个部分在屏幕上可见.我有MKMapView一个半透明视图部分覆盖的.我希望地图在视图下可见.我必须在地图上显示几个注释,并且我想使用它们缩放它们-setRegion:animated:,但是地图视图不尊重它被部分覆盖,因此我的一些注释将被半透明视图覆盖.

有没有办法告诉地图,像滚动视图一样使用contentInset?
更新:这是我尝试过的:
- (MKMapRect)mapRectForAnnotations
{
if (self.trafik) {
MKMapPoint point = MKMapPointForCoordinate(self.trafik.coordinate);
MKMapPoint deltaPoint;
if (self.map.userLocation &&
self.map.userLocation.coordinate.longitude != 0) {
MKCoordinateSpan delta = MKCoordinateSpanMake(fabsf(self.trafik.coordinate.latitude-self.map.userLocation.coordinate.latitude),
fabsf(self.trafik.coordinate.longitude-self.map.userLocation.coordinate.longitude));
deltaPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(delta.latitudeDelta, delta.longitudeDelta));
} else {
deltaPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(0.01, 0.01));
}
return MKMapRectMake(point.x, point.y, deltaPoint.x, deltaPoint.y);
} else {
return MKMapRectNull;
}
}
Run Code Online (Sandbox Code Playgroud)
Jak*_*lář 12
使用UIViews的layoutMargins。
例如,这将强制当前用户的位置引脚向上移动50pts。
mapView.layoutMargins = UIEdgeInsets(top: 0.0, left: 0.0, bottom: 100.0, right: 0.0)
Run Code Online (Sandbox Code Playgroud)
您可以执行以下操作,但这可能会干扰您UIViewController使用的其他视图bottomLayoutGuide。您必须对其进行测试才能找到答案。
覆盖bottomLayoutGuide将UIViewController您的地图作为子视图并返回一个MyLayoutGuide如下所示的对象:
@interface MyLayoutGuide : NSObject <UILayoutSupport>
@property (nonatomic) CGFloat length;
-(id)initWithLength:(CGFloat)length;
@end
@implementation MyLayoutGuide
@synthesize length = _length;
@synthesize topAnchor = _topAnchor;
@synthesize bottomAnchor = _bottomAnchor;
@synthesize heightAnchor = _heightAnchor;
- (id)initWithLength:(CGFloat)length
{
if (self = [super init]) {
_length = length;
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
bottomLayoutGuide插入MKMapView点50:
- (id)bottomLayoutGuide
{
CGFloat bottomLayoutGuideLength = 50.f;
return [[MyLayoutGuide alloc] initWithLength:bottomLayoutGuideLength];
}
Run Code Online (Sandbox Code Playgroud)
如果底部的时间表改变大小,您可以通过调用setNeedsLayout您的命令来强制重新计算此“插入” 。MKMapView我们在MKMapView子类中创建了一个可以从父类调用的助手UIViewController:
- (void)updateBottomLayoutGuides
{
// this method ends up calling -(id)bottomLayoutGuide on its UIViewController
// and thus updating where the Legal link on the map should be.
[self.mapView setNeedsLayout];
}
Run Code Online (Sandbox Code Playgroud)
答案改编自这个答案。