我通常在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