Tôi đã tải xuống dự án XCode từ liên kết bạn đã đề cập và có thể tạo lại lỗi. Câu trả lời sau đây có một cách giải quyết mà làm việc cho tôi
MKMapView Not Calling regionDidChangeAnimated on Pan
Để thuận tiện tôi muốn lặp lại các giải pháp và làm thế nào tôi áp dụng nó trong các dự án nêu
Trong CustomCalloutViewController.h
thêm UIGestureRecognizerDelegate
@interface CustomCalloutViewController : UIViewController
<MKMapViewDelegate, UIGestureRecognizerDelegate>
Trong CustomCalloutViewController.m
theo phương pháp viewDidLoad
thêm trước [super viewDidLoad];
if (NSFoundationVersionNumber >= 678.58){
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureCaptured:)];
pinch.delegate = self;
[mapView addGestureRecognizer:pinch];
[pinch release];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureCaptured:)];
pan.delegate = self;
[mapView addGestureRecognizer:pan];
[pan release];
}
Sau đó vẫn còn trong CustomCalloutViewController.m
thêm dòng sau
#pragma mark -
#pragma mark Gesture Recognizers
- (void)pinchGestureCaptured:(UIPinchGestureRecognizer*)gesture{
if(UIGestureRecognizerStateEnded == gesture.state){
///////////////////[self doWhatYouWouldDoInRegionDidChangeAnimated];
}
}
- (void)panGestureCaptured:(UIPanGestureRecognizer*)gesture{
if(UIGestureRecognizerStateEnded == gesture.state){
NSLog(@"panGestureCaptured ended");
// *************** Here it is *********************
///////////////////[self doWhatYouWouldDoInRegionDidChangeAnimated];
// *************** Here it is *********************
}
}
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
return YES;
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch: (UITouch *)touch{
return YES;
}
Edit: Tôi đã tìm thấy một workaround here (tất cả xuống ở phía dưới workaround trên được đề cập, quá). Tôi đã không thử, nhưng âm thanh promissing. Tôi lặp lại tại đây:
Giải pháp thay thế của tôi rất đơn giản: Trong trình điều khiển chế độ xem của bạn, tạo MKMapView trong chế độ xemDidAppear :, và hủy nó trong chế độ xemDidDisappear :. Tôi nhận ra đây không phải là giải pháp thân thiện cho những người sử dụng Trình tạo giao diện, nhưng theo quan điểm của tôi, đó là cách làm sạch nhất và có lẽ là cách tốt nhất để tiết kiệm bộ nhớ trong ứng dụng của bạn.
Chúng tôi thực sự đã phát hiện ra điều này xảy ra trên dự án ban đầu mà mọi người đang sử dụng làm mẫu trên trình mô phỏng iOS 5.1, vì vậy nó không phải là mã của tôi. Tôi sẽ thử thay thế didSelectView bằng các quan sát viên và xem điều gì xảy ra. –
Tôi cũng gặp phải vấn đề này, nó dường như xảy ra khi nhấp vào ghim và giữ trong khi đang tải một bộ ghim mới. – ThePower