2012-09-05 30 views
1

林按壓位置的座標有MapView的。我加入這個作爲視圖控制器的看法子視圖。我在viewDidLoad中下面的代碼:添加Alertview與在圖形頁面

[self.view addSubview:mapView]; 
    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mapLongPress:)]; 
    longPressGesture.minimumPressDuration = 2; 
    [mapView addGestureRecognizer:longPressGesture]; 
    [longPressGesture release]; 

而且,

- (void)mapLongPress:(UILongPressGestureRecognizer *)gestureRecognizer{ 
    NSLog(@"Gesture"); 
    if(gestureRecognizer.state == UIGestureRecognizerStateBegan){ 
     CGPoint touchLocation = [gestureRecognizer locationInView:mapView]; 

     CLLocationCoordinate2D coordinate; 
     coordinate = [mapView convertPoint:touchLocation toCoordinateFromView:mapView]; 

這些我從計算器得到。但其沒有工作..難道我需要做的事情更多的是什麼?

嘗試增加 [self.view addSubview:mapView];[mapView addGestureRecognizer:longPressGesture];
+0

是否mapLongPress:方法被調用?你能打印「座標」嗎? – iOS

+2

號。該方法不會被調用 – Vanitha

回答

1

UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mapLongPress:)]; 
longPressGesture.minimumPressDuration = 2; 
longPressGesture.delegate = self; 
[self.mapView addGestureRecognizer:longPressGesture]; 
[self.view addSubview:mapView]; 
[longPressGesture release]; 
+0

讓我試試..... – Vanitha

+0

沒有它不是現在的工作太.. – Vanitha

+0

我得到這個...如何獲取座標此代碼後顯示AlertView – Vanitha

1

只需添加UIGestureRecognizerDelegate到視圖控制器,做由我給上面的代碼!

0

試試這個:

UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] 
             initWithTarget:self action:@selector(mapLongPress:)]; 
lpgr.minimumPressDuration = 2.0; 

[self.mapView addGestureRecognizer:lpgr]; 

這是使用ARC,所以我不知道是否應該在這一刻釋放手勢現在。嘗試它而不釋放它,然後嘗試釋放它。看看是否會影響手勢。

+0

做u有想法diaplaying在AlertView緯度= XXX經度以下格式= YYY – Vanitha

+0

對不起,我不明白 – MCKapur

+0

它的K I找到了答案:-) – Vanitha