1
在我的應用程序中,我添加了一個MKMapView作爲UITableView的ontop視圖。 MapView的高度爲250,可見區域爲80. 每當找到某個位置時,我都希望將該位置(註釋)居中在MapView的底部80px的可見區域中。將中心映射到可見區域
這是我到目前爲止有:https://dl.dropbox.com/u/3077127/MapViewDemo.mov
我已經嘗試了一堆不同的東西,但我不能找到一個解決方案。我刪除了我現在測試的東西。 這是我的代碼:
float kMapHeaderHeight = 250.0f;
float kMapContentInset = 80.0f;
BOOL favFirstPositionFound = NO;
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:NSLocalizedString(@"Favorites", @"FavoritesViewController")];
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, -kMapHeaderHeight, self.tableView.frame.size.width, kMapHeaderHeight)];
[self.mapView setShowsUserLocation:YES];
[self.mapView setDelegate:self];
[self.mapView setUserInteractionEnabled:NO];
[self.tableView addSubview:self.mapView];
self.tableView.contentInset = UIEdgeInsetsMake(kMapContentInset, 0.0f, 0.0f, 0.0f);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.isDragging) {
if (self.tableView.contentOffset.y < kMapContentInset-((self.view.bounds.size.height/3)*2))
{
NSLog(@"Far enough!");
}
}
}
[...]
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
location=newLocation.coordinate;
MKCoordinateRegion region;
region.center=location;
MKCoordinateSpan span;
if (!favFirstPositionFound)
{
span.latitudeDelta=.010;
span.longitudeDelta=.010;
}
else {
span.latitudeDelta = self.mapView.region.span.latitudeDelta;
span.longitudeDelta = self.mapView.region.span.longitudeDelta;
}
region.span=span;
favFirstPositionFound = YES;
[self.mapView setRegion:region animated:YES];
[self.locationManager stopUpdatingLocation];
}
找到一個我需要修復的bug,就是如果你向上拉桌子,那麼節頭將保持其位置,但是內容將向上滾動到地圖視圖中。 –