如何停止viewForAnnotation方法覆盖iOS中的默认用户位置蓝色信标
2019年08月06日
作者:佚名
现在我用填充填充地图视图,并显示用户的当前位置.使用viewForAnnotation方法,它会使用默认的红色引脚覆盖所有注释,但是我想返回其他注释的视图,但将用户位置保留为默认的蓝色信标.有没有办法这样做,或者我必须创建一个新的注释视图,并根据注释返回正确的?
现在我有这样的东西:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { if (annotation.coordinate == locationManager.location.coordinate) { return nil; }else { MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Beacon"]; // Button UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; button.frame = CGRectMake(0,23,23); annotationView.rightCalloutAccessoryView = button; annotationView.canShowCallout = YES; return annotationView; } }
但是我不能等于两个,因为我不能从坐标参数中获取坐标属性.
有谁知道任何解决方案吗?
解决方法
在这里查看文档:
http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html
正如它所说:
If the object in the annotation parameter is an instance of the
MKUserLocation class,you can provide a custom view to denote the
user’s location. To display the user’s location using the default
system view,return nil.
所以你可以添加一个条件来检查:
if([annotation isKindOfClass: [MKUserLocation class]]) { return nil; }
以上是来客网为你收集整理的如何停止viewForAnnotation方法覆盖iOS中的默认用户位置蓝色信标全部内容,希望文章能够帮你解决如何停止viewForAnnotation方法覆盖iOS中的默认用户位置蓝色信标所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。