このコードは、通常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を使用しています。 –