因此,自从iOS7.1问世以来,当用户点击地图时,我的代码在选择地图上的新注释时就一直存在问题。代码在iOS6和7上都能找到,但在7.1上就搞砸了。
我没有找到关于这个问题的任何具体信息,但这里有我的非常简单的代码来说明这个问题。
我的头只包含以下内容:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MAViewController : UIViewController <MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *mMapView;
@end我的实现文件如下:
#import "MAViewController.h"
@interface MAViewController ()
@end
@implementation MAViewController
@synthesize mMapView;
- (void)viewDidLoad
{
[super viewDidLoad];
[self.mMapView setDelegate:self];
[self.mMapView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mapTapped:)]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)mapTapped:(UITapGestureRecognizer *)recognizer
{
CGPoint touchPoint = [recognizer locationInView:self.mMapView];
CLLocationCoordinate2D touchMapCoordinate = [self.mMapView convertPoint:touchPoint toCoordinateFromView:self.mMapView];
CLLocation *lTapLocation = [[CLLocation alloc] initWithLatitude:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude];
[self.mMapView removeAnnotations:mMapView.annotations];
MKPointAnnotation *lAnnotation = [[MKPointAnnotation alloc] init];
lAnnotation.coordinate = lTapLocation.coordinate;
lAnnotation.title = @"TAP";
[self.mMapView addAnnotation:lAnnotation];
}
#pragma mark - MapView Delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if([annotation isKindOfClass: [MKUserLocation class]]) {
return nil;
}
MKPinAnnotationView *lPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
lPin.canShowCallout = FALSE;
return lPin;
}
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *lAnnotationView = (MKAnnotationView*)[views objectAtIndex:0];
lAnnotationView.canShowCallout = YES;
if ([lAnnotationView.annotation isKindOfClass:[MKUserLocation class]]) {
return;
}
[mapView selectAnnotation:lAnnotationView.annotation animated:YES];
}
@end我只是在故事板中添加了一个MKMapView,仅此而已。感谢你分享你对这个问题的看法。
问题是,注释一次被选中和取消选中,用户需要再次点击它才能显示标题。
发布于 2014-07-08 14:59:23
我知道这个问题是两个月前提出的,但我现在也面临着同样的问题。
目前,我正在使用一种变通方法,在将注释添加到mapView之后,选择注释时会有一个小小的延迟。这似乎适用于延迟>= 0.4s。但当延迟小于0.4s时,它会在选择后立即取消选择。非常奇怪:
//In the onClick handler
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = tapCoord;
self.lastAnnotation = annotation;
[self.mapView addAnnotation:annotation];
[self performSelector:@selector(selectLastAnnotation) withObject:nil afterDelay:0.4];和helper方法:
-(void)selectLastAnnotation{
[self.mapView selectAnnotation:self.lastAnnotation animated:YES];
}https://stackoverflow.com/questions/23015140
复制相似问题