Ios 自定义地图注释详图索引-如何控制宽度
我已成功地从中实现了自定义地图注释详图索引代码。 (当用户点击地图别针时,我会显示自定义图像,而不是标准详图索引视图) 剩下的唯一问题是标注占据了视图的整个宽度,如果宽度与我使用的图像相对应,应用程序看起来会更好 我已经对MKAnnotationView进行了子类化,当我将其contentWidth设置为图像的宽度时,三角形并不总是指向插针,或者图像甚至不在包装器视图内 任何帮助或建议都会很好。Ios 自定义地图注释详图索引-如何控制宽度,ios,callouts,mapkit,Ios,Callouts,Mapkit,我已成功地从中实现了自定义地图注释详图索引代码。 (当用户点击地图别针时,我会显示自定义图像,而不是标准详图索引视图) 剩下的唯一问题是标注占据了视图的整个宽度,如果宽度与我使用的图像相对应,应用程序看起来会更好 我已经对MKAnnotationView进行了子类化,当我将其contentWidth设置为图像的宽度时,三角形并不总是指向插针,或者图像甚至不在包装器视图内 任何帮助或建议都会很好。 谢谢。我在为iPad实现Callout MapAnnotationView时遇到了类似的问题。基本
谢谢。我在为iPad实现Callout MapAnnotationView时遇到了类似的问题。基本上,我不希望iPad版占据地图视图的全部宽度 在
prepareFrameSize
方法中设置宽度:
- (void)prepareFrameSize {
// ...
// changing frame x/y origins here does nothing
frame.size = CGSizeMake(320.0f, height);
self.frame = frame;
}
接下来,必须根据parentAnnotationView计算xOffset:
- (void)prepareOffset {
// Base x calculations from center of parent view
CGPoint parentOrigin = [self.mapView convertPoint:self.parentAnnotationView.center
fromView:self.parentAnnotationView.superview];
CGFloat xOffset = 0;
CGFloat mapWidth = self.mapView.bounds.size.width;
CGFloat halfWidth = mapWidth / 2;
CGFloat x = parentOrigin.x + (320.0f / 2);
if( parentOrigin.x < halfWidth && x < 0 ) // left half of map
xOffset = -x;
else if( parentOrigin.x > halfWidth && x > mapWidth ) // right half of map
xOffset = -( x - mapWidth);
// yOffset calculation ...
}
希望这能帮助您走上正轨。嘿,非常感谢您提供的代码+1但我仍然不知道如何让标注底部的三角形直接指向地图,这有很多问题。你能在这里给我一些指导吗?或者我应该提出另一个问题吗?这是我的尝试,在需要和自然准备的adjustMapRegionIfNeeded和PrepareOffsetX方面遇到了最大的问题,这就打开了一个新的问题:
- (void)drawRect:(CGRect)rect {
// ...
// Calculate the carat lcation in the frame
if( self.centerOffset.x == 0.0f )
parentX = 320.0f / 2;
else if( self.centerOffset.x < 0.0f )
parentX = (320.0f / 2) + -self.centerOffset.x;
//...
}