【问题标题】:MKPinAnnotationView draggable not working. draggable = YES, callout has title and subtitle, and setCoordinate is implemented可拖动的 MKPinAnnotationView 不起作用。 draggable = YES,callout有title和subtitle,setCoordinate实现
【发布时间】:2013-03-15 10:27:32
【问题描述】:

当我尝试拖动图钉时,它不会移动。当我触摸它时,它会变暗。但是,它永远不会抬起,也永远不会移动。

这是我的注释类的头文件:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <Parse/Parse.h>

@interface GeoPointAnnotation : NSObject <MKAnnotation>

- (id)initWithObject:(PFObject *)aObject;

@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;

- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;

@end

这是我在视图控制器中创建注释的地方:

- (void)updateMap
{
    [self.mapView removeAnnotations:self.mapView.annotations];

    PFGeoPoint *geoPoint = [self.post location];

    // center the map around the geopoint
    [self.mapView setRegion:MKCoordinateRegionMake(
       CLLocationCoordinate2DMake(geoPoint.latitude, geoPoint.longitude),
       MKCoordinateSpanMake(0.01, 0.01)
       )];

    GeoPointAnnotation *annotation = [[GeoPointAnnotation alloc] initWithObject:self.post.object];
    [self.mapView addAnnotation:annotation];
}

// from Geolocations by Parse
#pragma mark - MKMapViewDelegate

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    static NSString *GeoPointAnnotationIdentifier = @"RedPin";

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:GeoPointAnnotationIdentifier];

    if (!annotationView) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:GeoPointAnnotationIdentifier];
        annotationView.pinColor = MKPinAnnotationColorRed;
        annotationView.canShowCallout = YES;
        annotationView.draggable = YES;
        annotationView.animatesDrop = YES;
    }

    return annotationView;
}

有什么想法吗?

【问题讨论】:

标签: objective-c iphone ios6 mapkit


【解决方案1】:

发现问题:我忘记在我的 Storyboard xib 中连接 Map View 的委托。 h/t Nitin Gohel - 谢谢!

【讨论】:

  • 我也是!你不是一个人。您应该接受您作为答案发布。
猜你喜欢
  • 2012-12-10
  • 2017-04-10
  • 1970-01-01
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 2013-01-15
  • 1970-01-01
  • 2014-01-12
相关资源
最近更新 更多