根据Apple文档,MKPinAnnotationView的针脚颜色有红色,绿色和紫色可供选择.有没有办法得到其他颜色?我在文档中找不到任何内容.
我正在尝试捕捉我的点击事件MKMapView,这样我就可以MKPinAnnotation在用户点击的点上删除.基本上我有一个覆盖的地图MKOverlayViews(显示建筑物的叠加层),我想通过删除MKPinAnnotaion并在标注中显示更多信息来为用户提供有关该叠加的更多信息.谢谢.
mkpinannotationview mkmapview ios4 mkoverlay uitapgesturerecognizer
在调用MKMapView的setCenterCoordinate:animated:方法(没有动画)后,我想调用selectAnnotation:animated :(带动画),以便从新居中的图钉中弹出注释.
现在,我只是观察mapViewDidFinishLoadingMap:然后选择注释.但是,这是有问题的.例如,当不需要加载其他地图数据时,不会调用此方法.在这些情况下,我的注释未被选中.:(
很好.我可以在设置中心坐标后立即调用它.啊,但在这种情况下,它也有可能存在的地图数据加载(但还没有完成加载还).我冒险过早地调用它,动画最多也会变得不稳定.
因此,如果我理解正确,这不是知道我的坐标是否可见的问题,因为它可能几乎偏离屏幕距离并且必须加载新的地图数据.相反,它需要知道是否需要加载新的地图数据,然后相应地采取行动.
有关如何实现这一点的任何想法,或者如何在将注释生效的坐标重新定位到地图视图后以其他方式(可靠地)选择注释?
线索赞赏 - 谢谢!
我有一个自定义的MKAnnotationView,我在viewForAnnotation中自己设置我的图像.我如何使用MKPinAnnotationView为它设置动画效果?
我的代码是
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"blah.png"];
annotationView.annotation = annotation;
return annotationView;
}
Run Code Online (Sandbox Code Playgroud) cocoa-touch mapkit mkpinannotationview mkannotationview ios-4.2
我有一个实例,MKMapView并希望使用自定义注释图标,而不是MKPinAnnotationView提供的标准图钉图标.所以,我已经设置了一个名为CustomMapAnnotation的MKAnnotationView的子类,并且重写-(void)drawRect:了绘制CGImage.这有效.
当我尝试复制.animatesDropMKPinAnnotationView提供的功能时出现问题; 当注释被添加到MKMapView实例时,我希望我的图标能够逐渐显示,从上到下以及从左到右顺序显示.
这是 - (void)drawRect:用于CustomMapAnnotation,当你只绘制UIImage(这是第二行所做的)时它可以工作:
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
[((Incident *)self.annotation).smallIcon drawInRect:rect];
if (newAnnotation) {
[self animateDrop];
newAnnotation = NO;
}
}
Run Code Online (Sandbox Code Playgroud)
添加animateDrop方法时出现问题:
-(void)animateDrop {
CGContextRef myContext = UIGraphicsGetCurrentContext();
CGPoint finalPos = self.center;
CGPoint startPos = CGPointMake(self.center.x, self.center.y-480.0);
self.layer.position = startPos;
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"position"];
theAnimation.fromValue=[NSValue valueWithCGPoint:startPos];
theAnimation.toValue=[NSValue valueWithCGPoint:finalPos];
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
theAnimation.delegate = self;
theAnimation.beginTime = 5.0 * (self.center.x/320.0);
theAnimation.duration = 1.0;
[self.layer addAnimation:theAnimation …Run Code Online (Sandbox Code Playgroud) 我想在MKMapView上创建一个自定义标注气泡.但我想以与默认气泡相同的方式创建呼出气泡.那么如何在此图像中创建一个类似于注释的视图 替代文本http://blog.objectgraph.com/wp-content/uploads/2009/04/mapkit31.png
我想要一个自定义自定义视图,在下图中看起来像"停放位置"注释.具有自定义宽度,高度等
我无法在默认气泡中添加所需的详细信息.这就是为什么要创建自定义泡泡.
Plz帮帮我..谢谢..
我对MKMapKit的局限性感到相当沮丧.我当前的问题与注释视图的z排序有关,特别是当它与触摸相关时.如果您接受默认的z顺序,mapkit会为您提供:
我尝试使用与Web上的以下代码类似的东西来解决#1(其设计旨在对z顺序进行一些控制)
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
for (MKAnnotationView * annView in views) {
TopBottomAnnotation * ann = (TopBottomAnnotation *) [annView annotation];
if ([ann top]) {
[[annView superview] bringSubviewToFront:annView];
} else {
[[annView superview] sendSubviewToBack:annView];
}
}
}
运行传递给mapView的注释视图:didAddAnnotationViews:并调整它们的z顺序确实似乎修复了#1.问题是现在标注视图不再总是位于注释视图的顶部.MapKit似乎对图层感到非常困惑(应在所有注释视图上方的图层中绘制标注).我甚至可以弄清楚它是如何混淆的,因为你收到的所有MKAnnotationViews都有相同的superview(私有类MKOverlayView).您会认为任何合理的设计都会绘制有关此叠加视图的标注.
有没有人成功解决了#1或#2?
MKPinAnnotationView引脚的宽度和高度(以像素为单位)是多少?
编辑:更具体地说,iPhone屏幕上包含引脚的虚构矩形的宽度和高度.
我在MapView上显示用户头像图像.如果在没有动画的情况下渲染它们,它们似乎正在工作,但是我想为它们的动画制作动画.如果我将pinView.animatesDrop设置为true,那么我将丢失头像并将其替换为pin.如何在不使用针的情况下为我的头像添加动画效果?
这是我正在使用的viewForAnnotation方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView* pinView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"MyAnnotation"];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotation"];
}
else
pinView.annotation = annotation;
//If I set this to true, my image is replaced by the pin
//pinView.animatesDrop = true;
//I'm using SDWebImage
[pinView setImageWithURL:[NSURL URLWithString:@"/pathtosomeavatar.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
//Adding a nice drop shadow here
pinView.layer.shadowColor = [UIColor blackColor].CGColor;
pinView.layer.shadowOffset = CGSizeMake(0, 1);
pinView.layer.shadowOpacity = 0.5;
pinView.layer.shadowRadius = 3.0;
return pinView; …Run Code Online (Sandbox Code Playgroud) 我一直试图在mapview上放置一个可拖动的注释多年.(我正在使用默认的引脚,而不是我自己的引脚)到目前为止,我只能在设定的坐标处显示它(实际上并不是很大的成就),我需要首先获得注释以对选择作出反应,它不会永远不会被这个didChangeDragState功能所接受.然后我需要能够拖动它,将它放在一个新的位置并获得新位置的坐标.
我对Swift来说是个新手,但我已经开始了一个相当困难的项目.我看了几乎所有我在google上寻找" MKAnnotationSwift中的可拖动mapkit"和类似变体的东西.(编辑:我没有找到任何解释我的问题的答案,所有其他答案都提供了如何上传个性化的答案MKAnnotation.他们都有标题字段,但没有一个答案提到标题字段是必要的,结果证明是主要的问题.他们只提到我应该设置dragState来控制引脚的移动,但在我的情况下,这看起来是不正确的,如下所示)无论如何 !下面是我的代码,我尝试实现mapView并添加注释.
var currentLat:CLLocationDegrees!
var currentLong:CLLocationDegrees!
var currentCoordinate:CLLocationCoordinate2D!
....
override func viewDidAppear(animated: Bool) {
let annotation = PinAnnotationClass()
annotation.setCoordinate(currentCoordinate)
//annotation.setCoordinate(currentCoordinate)
//AnnotationView()
self.mapView.addAnnotation(annotation)
}
override func viewDidLoad() {
super.viewDidLoad()
println("hello!")
self.mapView.delegate = self
loadMap()
findPath()
}
func loadMap()
{
currentCoordinate = CLLocationCoordinate2DMake(currentLat, currentLong)
var mapSpan = MKCoordinateSpanMake(0.01, 0.01)
var mapRegion = MKCoordinateRegionMake(currentCoordinate, mapSpan)
self.mapView.setRegion(mapRegion, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
随着扩展:
extension DetailsViewController: MKMapViewDelegate {
func mapView(mapView: MKMapView!,
viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation …Run Code Online (Sandbox Code Playgroud) mapkit ×6
mkmapview ×5
ios ×4
iphone ×4
cocoa-touch ×2
ios4 ×2
objective-c ×2
ios-4.2 ×1
mkoverlay ×1
swift ×1