林按壓位置的座標有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];
是否mapLongPress:方法被調用?你能打印「座標」嗎? – iOS
號。該方法不會被調用 – Vanitha