【问题标题】:iPad and MapKit -Can't Get Draggable Marker to DragiPad 和 MapKit - 无法拖动可拖动标记
【发布时间】:2012-04-14 01:18:43
【问题描述】:

我有点生气,在这里。

据我所知,我做的一切都是正确的。

我正在按照this posting 中所说的做,但没有骰子。

基本问题是可拖动标记不会拖动。

这里是麻烦点。我想将一个简单的黑色标记(基类是一个不可拖动的黑色标记)专门化为可拖动的。

这是它的界面:

/**************************************************************//**
 \class BMLT_Search_BlackAnnotationView
 \brief We modify the black annotation view to allow dragging.
 *****************************************************************/
@interface BMLT_Search_BlackAnnotationView : BMLT_Results_BlackAnnotationView

@property (nonatomic,readwrite,assign) CLLocationCoordinate2D   coordinate;

- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier coordinate:(CLLocationCoordinate2D)inCoordinate;
@end

这是它的实现:

/**************************************************************//**
 \class BMLT_Search_BlackAnnotationView
 \brief We modify the black annotation view to allow dragging.
 *****************************************************************/
@implementation BMLT_Search_BlackAnnotationView
@synthesize coordinate;

/**************************************************************//**
 \brief We simply switch on the draggable bit, here.
 \returns self
 *****************************************************************/
- (id)initWithAnnotation:(id<MKAnnotation>)annotation
         reuseIdentifier:(NSString *)reuseIdentifier
              coordinate:(CLLocationCoordinate2D)inCoordinate
{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];

    if ( self )
        {
        [self setDraggable:YES];
        [self setCoordinate:inCoordinate];
        }

    return self;
}

/**************************************************************//**
 \brief Handles dragging.
 *****************************************************************/
- (void)setDragState:(MKAnnotationViewDragState)newDragState
            animated:(BOOL)animated
{
#ifdef DEBUG
    NSLog(@"BMLT_Search_BlackAnnotationView setDragState called with a drag state of %@.", newDragState);
#endif
    self.dragState = newDragState;
}

@end

setDragState:动画:永远不会被调用。

据我所知,我做的一切都是正确的。

显然,我不是。

有什么想法吗?

这里是设置和回调:

/**************************************************************//**
 \brief  If this is an iPad, we'll set up the map.
 *****************************************************************/
- (void)setUpMap
{
    if ( mapSearchView )    // This will be set in the storyboard.
        {
#ifdef DEBUG
        NSLog(@"A_BMLT_SearchViewController setUpIpadMap called (We're an iPad, baby!).");
#endif
        BMLTAppDelegate *myAppDelegate = [BMLTAppDelegate getBMLTAppDelegate];  // Get the app delegate SINGLETON

        CLLocationCoordinate2D  center;
#ifdef DEBUG
        NSLog(@"A_BMLT_SearchViewController setUpIpadMap We're using the canned coordinates.");
#endif
        center.latitude = [NSLocalizedString(@"INITIAL-MAP-LAT", nil) doubleValue];
        center.longitude = [NSLocalizedString(@"INITIAL-MAP-LONG", nil) doubleValue];

        if ( [myAppDelegate myLocation] )
            {
#ifdef DEBUG
            NSLog(@"A_BMLT_SearchViewController setUpIpadMap We know where we are, so we'll set the map to that.");
#endif
            center = [myAppDelegate myLocation].coordinate;
            }

        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 25000, 25000);

        [mapSearchView setRegion:region animated:NO];

        BMLT_Results_MapPointAnnotation *myMarker = [[BMLT_Results_MapPointAnnotation alloc] initWithCoordinate:center andMeetings:nil];

        [myMarker setTitle:@"Marker"];

        [mapSearchView addAnnotation:myMarker];

        if ( [[BMLT_Prefs getBMLT_Prefs] keepUpdatingLocation] )    // If the user wants us to keep track of them, then we'll do so.
            {
            [mapSearchView setUserTrackingMode:MKUserTrackingModeFollow animated:YES];
            }
        else
            {
            [mapSearchView setUserTrackingMode:MKUserTrackingModeNone animated:NO];
            }
        }
}

#pragma mark - MkMapAnnotationDelegate Functions -

/**************************************************************//**
 \brief Returns the view for the marker in the center of the map.
 \returns an annotation view, representing the marker.
 *****************************************************************/
- (MKAnnotationView *)mapView:(MKMapView *)mapView
            viewForAnnotation:(id < MKAnnotation >)annotation
{
#ifdef DEBUG
    NSLog(@"A_BMLT_SearchViewController viewForAnnotation called.");
#endif
    static NSString* identifier = @"single_meeting_annotation";

    MKAnnotationView* ret = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if ( !ret )
        {
        ret = [[BMLT_Search_BlackAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier coordinate:[annotation coordinate]];
        }

    return ret;
}

【问题讨论】:

    标签: iphone ios mapkit draggable markers


    【解决方案1】:

    您需要将您的注释视图设置为可拖动。

    [ret setDraggable:YES]
    

    【讨论】:

    • 谢谢。这是在实际的视图类中完成的。但是,我想我知道问题出在哪里。看起来标记的命中测试区域是默认图钉,而不是我的新图标,它更宽。如果我在图钉所在的位置右击,我可以拖动。
    • 其实我觉得这是模拟器加剧的问题。我正在使用触控板和精确指针。如果我将图像准确地钉在中心,我可以拖动。它周围有几个像素没有做任何事情,然后是背景图。我怀疑在真实设备中使用我的hamlike爪子每次都会起作用。当 SO 允许时,我会发布答案。
    【解决方案2】:

    只是想在这里报告真正的问题:

    PEBCAK

    问题是图标上的拖动目标很小。使用模拟器时,操纵器(光标)也很小,因此将它们排列起来可能是一个挑战。

    在设备上用我的手指更好,虽然那也很抽搐。

    顺便说一句:地图的代码现在与上面的不同。我修复了一些其他问题。

    如果有人想看代码,整个项目都是开源的 (GitHub -Look up BMLT IOS)。我目前在 2.0 分支工作,并且会工作一段时间,所以它是一个移动的目标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      相关资源
      最近更新 更多