我试图将MKMapView放在一些UiTableViewCell中,但是(在iPhone 5上,甚至在其他设备中),当应用程序使用地图加载单元格时,滚动变得不太顺畅.
有一些方法,使用GCD或其他方法,以更好的方式做到这一点?
以下是结果的屏幕截图:
我从Nib加载Cell,这里是我设置坐标和注释的代码(使用自定义视图,但这不是问题.)
// Delegate cell.objectMap.delegate = self; // Coordinate MKCoordinateRegion region; region.center = activity.object.location.coordinate; MKCoordinateSpan span; span.latitudeDelta = 0.055; span.longitudeDelta = 0.055; region.span = span; [cell.objectMap setRegion:region animated:NO]; // Add an annotation MKPointAnnotation *point = [[MKPointAnnotation alloc] init]; point.coordinate = activity.object.location.coordinate; [cell.objectMap addAnnotation:point]; // Show the MKMapView in the cell cell.objectMap.hidden = NO;
Monte.. 15
我最终将MKMapSnapshotter用于支持这种超棒和快速功能的设备,并使用Google Static Maps Api来运行运行iOS6的设备.我认为这是我能得到的最好,最快的解决方案.
感谢@Rob的建议.
if ( IS_IOS7 ) { // Placeholder cell.objectImage.image = [UIImage imageNamed:@"mapPlaceholder"]; // Cooridinate MKCoordinateRegion region; region.center = activity.object.location.coordinate; MKCoordinateSpan span; span.latitudeDelta = 0.055; span.longitudeDelta = 0.055; region.span = span; [self.mapViewForScreenshot setRegion:region animated:NO]; MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init]; options.region = self.mapViewForScreenshot.region; options.scale = [UIScreen mainScreen].scale; options.size = CGSizeMake(300, 168); MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options]; [snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) { UIImage *image = snapshot.image; [cell.objectImage setImage:image]; cell.mapPinImageView.hidden = NO; }]; }else{ cell.mapPinImageView.hidden = NO; [cell.objectImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=14&size=600x338&maptype=roadmap&sensor=false&key=APIKEY",activity.object.location.coordinate.latitude, activity.object.location.coordinate.longitude]] placeholderImage:nil]; }
我最终将MKMapSnapshotter用于支持这种超棒和快速功能的设备,并使用Google Static Maps Api来运行运行iOS6的设备.我认为这是我能得到的最好,最快的解决方案.
感谢@Rob的建议.
if ( IS_IOS7 ) { // Placeholder cell.objectImage.image = [UIImage imageNamed:@"mapPlaceholder"]; // Cooridinate MKCoordinateRegion region; region.center = activity.object.location.coordinate; MKCoordinateSpan span; span.latitudeDelta = 0.055; span.longitudeDelta = 0.055; region.span = span; [self.mapViewForScreenshot setRegion:region animated:NO]; MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init]; options.region = self.mapViewForScreenshot.region; options.scale = [UIScreen mainScreen].scale; options.size = CGSizeMake(300, 168); MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options]; [snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) { UIImage *image = snapshot.image; [cell.objectImage setImage:image]; cell.mapPinImageView.hidden = NO; }]; }else{ cell.mapPinImageView.hidden = NO; [cell.objectImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=14&size=600x338&maptype=roadmap&sensor=false&key=APIKEY",activity.object.location.coordinate.latitude, activity.object.location.coordinate.longitude]] placeholderImage:nil]; }