我通常在iOS 4.3中運行此代碼。但是當我將項目更改爲iOS 5.0時,我無法滾動和縮放地圖。MKMapView無法滾動和放大iOS 5.0
有人可以告訴我爲什麼有這個問題?我該如何解決它?
的代碼是:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect rect = CGRectMake(0, 0, 320, 460);
map = [[MKMapView alloc] initWithFrame:rect];
map.showsUserLocation = YES;
MKUserLocation *userLocation = map.userLocation;
[userLocation addObserver:self forKeyPath:@"location"
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial
context:nil];
map.scrollEnabled = YES;
map.zoomEnabled = YES;
map.mapType = MKMapTypeStandard;
[self.view addSubview:map];
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([change objectForKey:NSKeyValueChangeNewKey] != [NSNull null]) {
MKCoordinateRegion region;
CLLocationCoordinate2D testCoordinate;
double lat = 22.195579570451734;
double lng = 113.542275265336;
testCoordinate.latitude = lat;
testCoordinate.longitude = lng;
region.center = testCoordinate;
MKCoordinateSpan span;
span.latitudeDelta = 0.0011;
span.longitudeDelta = 0.0011;
region.span = span;
[map setRegion:region animated:YES];
}
}
安娜你說得對,我使用mapView:didUpdateUserLocation:現在工作正常,非常感謝! – 2011-12-21 09:51:46