나는 드래그 할 수있는 MKAnnotationView
을 가지고 있는데, 드래그의 시작과 끝에서 연속적이 아닌 콜백을받는 didChangeDragState:
대리자 메소드를 구현했습니다. 내가 끌고있는 주석의 현재 좌표를 추적하고 싶습니다. 제발 좀 도와주세요. 고맙습니다.MKAnnotationView를 끌 때 연속 호출을 얻는 방법
2
A
답변
0
는 annotationview.coordinates에서 가져온 할 수 있습니다 좌표 :
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:
(MKAnnotationViewDragState)oldState
{
CLLocationCoordinate2D currentCoordinates = view.annotation.coordinate;
}
+0
는이 방법 만 호출 될 때 주석 뷰의 드래그 상태가 한 상태에서 다른 상태로 변경되면 뷰가 드래그 될 때 연속적으로 호출되지 않습니다. 'Dragging' 상태로 바뀔 때 한 번만 호출됩니다. 또한 주석의 좌표는 상태가 '종료 됨'으로 바뀌면 업데이트되며 드래그하는 동안 업데이트되지 않습니다. – Ziewvater
0
는 지금까지 내가 아는 한,이 작업을 수행하기위한 애플에서 제공하는 방법이 아니라, 당신이 KVO를 통해 달성 할 수있다 (h/t = this answer).
MKAnnotationViewDragStateEnding
을 입력 할 때까지 주석 좌표가 업데이트되지 않으므로 수동으로 주석보기 좌표를 결정해야합니다.
는 전체 솔루션은 다음과 같습니다
// Somewhere in your code before the annotation view gets dragged, subscribe your observer object to changes in the annotation view's frame center
annotationView.addObserver(DELEGATE_OBJECT, forKeyPath: "center", options: NSKeyValueObservingOptions.New, context: nil)
// Then in the observer's code, fill out the KVO callback method
// Your observer will need to conform to the NSKeyValueObserving protocol -- all `NSObject`s already do
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
// Check that we're observing an annotation view. The `where` clause can be omitted if you're only observing changes in its frame, or don't care about extra calls
if let annotationView = object as? MKAnnotationView where keyPath == "center" {
// Defined below, `coordinateForAnnotationView` converts a CGPoint measured within a given MKMapView to the geographical coordinate represented in that location
let newCoordinate = coordinateForAnnotationView(pin, inMapView: self.mapView)
// Do stuff with `newCoordinate`
}
}
func coordinateForAnnotationView(annotationView: MKAnnotationView, inMapView mapView: MKMapView) -> CLLocationCoordinate2D {
// Most `MKAnnotationView`s will have a center offset, including `MKPinAnnotationView`
let trueCenter = CGPoint(x: annotationView.center.x - annotationView.centerOffset.x,
y: annotationView.center.y - annotationView.centerOffset.y)
return mapView.convertPoint(trueCenter, toCoordinateFromView: mapView)
}
관련 문제
- 1. WPF에서 개체를 끌 때 부드러운 애니메이션 효과를 얻는 방법
- 2. EXC_BAD_ACCESS, UIScrollView 끌 때
- 3. 요소를 끌 때 jquery로 요소를 찾는 방법
- 4. Google지도 마커를 끌 때 클릭하는 방법
- 5. MKAnnotationView를 프로그래밍 방식으로 호출하는 방법? (아이폰, MapKit)
- 6. SlidingDrawer를 끌 때 활동 호출
- 7. 화면에서 끌 때 UIImageView 바운스
- 8. 보기를 끌 때 애니메이션을 수행합니다.
- 9. 루비에서 백틱을 사용하여 서브 프로세스의 연속 출력을 얻는 방법
- 10. 도구 상자 (WPF)에서 컨트롤을 끌 때 명령을 연결하는 방법
- 11. 사용자가 내 페이지에서 개체를 끌 때 'I-Beam'커서를 방지하는 방법
- 12. 끌 때 Silverlight의 끌기 소스 인 UIElement에서 MouseLeave를 감지하는 방법?
- 13. JQuery : .LOAD, .LOAD가 완료된 후에 다음 호출을 얻는 방법?
- 14. xquery- 숫자 값 목록에서 연속 값의 차이를 얻는 방법
- 15. Rakefile에서 그들의 작업을 출력하도록 fileutils 호출을 얻는 방법?
- 16. MapKit에서 MKAnnotationView를 더 민감하게 만드는 방법은 무엇입니까?
- 17. MKAnnotationView를 탭하여 선택 취소하고 콜 아웃을 숨기기
- 18. 마우스를 끌 때 Jpanel에 선을 그립니다.
- 19. 개체를 끌 때 화면의 개체가 깜박이기 시작합니다.
- 20. 마우스를 끌 때 마우스가 원래 위치로 돌아갑니다
- 21. 끌 때 폼이 앞으로 가져 오지 않음
- 22. 도구 상자에서 끌 때 컨트롤이 나타나지 않는다.
- 23. div 외부로 끌 때 객체가 보이지 않도록하기
- 24. 스크롤을 사용하여 UITableView를 끌 때 행 선택
- 25. UITableView를 끌 때 performSelector를 실행할 수 없습니까?
- 26. 핀을 끌 때 자동 스크롤 mkmapview
- 27. 요소를 끌 때 swipeleft/-right를 깨기
- 28. 텍스트를 선택/끌 때 페이지 스크롤을 중지하십시오.
- 29. UIScrollview는 uiviews를 끌 때 스크롤 할 때만
- 30. 자바 스크립트에서 연속 달을 얻는 방법은 무엇입니까?
이 방법을 사용해보십시오 : 가'- (무효)지도보기 (MKMapView *)지도보기 regionDidChangeAnimated : (BOOL)가 animated' – Dhruv