2012-03-30 5 views
0

私は十字架になっています。iPadとMapKit - ドラッグするドラッグマーカーを取得しないでください

私が知る限り、私はすべてを正しく行っています。

私はそれが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; 
} 

答えて

1

あなたがドラッグ可能であるためにあなたのanootationのビューを設定する必要があります。

は、ここで設定し、コールバックです。

[ret setDraggable:YES] 
+0

ありがとうございました。これは実際のビュークラスで行われます。しかし、私は問題が何であるかを知っていると思う。マーカのヒットテスト領域は、新しいアイコンではなく、デフォルトのピンであるように見えます。ピンがどこにあるのかを右からクリックするとドラッグできます。 –

+0

実際、これはシミュレータによって悪化している問題だと私は考えています。私はトラックパッドと正確なポインタを使用しています。画像を正確に中央に釘付けすれば、ドラッグすることができます。周囲には何もしていないピクセルがいくつかあり、その後はバックグラウンドマップがあります。私は、実際のデバイスで私のハムのような足を使用すると、毎回動作すると思われる。私はそれが許すときに答えを掲示します。 –

0

ただ、ここでの本当の問題を報告したかった:

PEBCAK

問題は、アイコンをドラッグターゲットがティーニー、小さなであるということです。シミュレーターでは、マニピュレーター(カーソル)もわずかに小さいので、ライン上に挑戦することができます。

それは、あまりにも、落ち着きあるが、それは、私の指で、デバイス上の方が良いでしょう。

BTW:地図のコードは今では上記とは異なります。私は他のいくつかの問題を修正しました。

誰もがコードを見たい場合は、プロジェクト全体は、オープンソース(GitHub -Look up BMLT IOS)です。私は現在、2.0ブランチで作業していますし、しばらくの間、それは移動ターゲットです。

関連する問題