Objective c 调整MKMapView的大小
看起来很简单。但当我尝试使用setFrame方法调整大小时,我遇到了小故障。还有一些其他UIView使用setFrame方法调整了大小,它工作得非常好。我用滑动条和地图视图定制了应用程序。滑块更改MKMapView的X位置,但保持宽度等于屏幕宽度。这种方法适用于所有视图。但MKMapView的大小调整带来了平滑的问题。有人能告诉我为什么会发生这种情况,以及如何解决它吗?我也遇到了同样的问题,似乎只有iOS 6(苹果地图)出现了这种情况,而iOS 5(谷歌地图)没有出现这种情况 我的解决方案是,当用户开始拖动分隔器手柄时,拍摄地图的“屏幕截图”,在拖动过程中用此屏幕截图替换地图,并在松开手指时将地图放回原处 我使用了UIView屏幕截图的代码和Nikolai Ruhe在的答案作为一个漂亮的背景色 我的UIPangEstureRecognitor操作如下所示(在界面生成器上设置了自动调整大小的Objective c 调整MKMapView的大小,objective-c,mkmapview,frame,Objective C,Mkmapview,Frame,看起来很简单。但当我尝试使用setFrame方法调整大小时,我遇到了小故障。还有一些其他UIView使用setFrame方法调整了大小,它工作得非常好。我用滑动条和地图视图定制了应用程序。滑块更改MKMapView的X位置,但保持宽度等于屏幕宽度。这种方法适用于所有视图。但MKMapView的大小调整带来了平滑的问题。有人能告诉我为什么会发生这种情况,以及如何解决它吗?我也遇到了同样的问题,似乎只有iOS 6(苹果地图)出现了这种情况,而iOS 5(谷歌地图)没有出现这种情况 我的解决方案是,当
(MKMapView)self.map
是(UIView)self.mapContainer
的子视图):
- (IBAction)handleMapPullup:(UIPanGestureRecognizer *)sender
{
CGPoint translation = [sender translationInView:self.mapContainer];
// save current map center
static CLLocationCoordinate2D centerCoordinate;
switch (sender.state) {
case UIGestureRecognizerStateBegan: {
// Save map center coordinate
centerCoordinate = self.map.centerCoordinate;
// Take a "screenshot" of the map and set the size adjustments
UIImage *mapScreenshot = [UIImage imageWithView:self.map];
self.mapImage = [[UIImageView alloc] initWithImage:mapScreenshot];
self.mapImage.autoresizingMask = self.map.autoresizingMask;
self.mapImage.contentMode = UIViewContentModeCenter;
self.mapImage.clipsToBounds = YES;
self.mapImage.backgroundColor = [mapScreenshot mergedColor];
// Replace the map with a screenshot
[self.map removeFromSuperview];
[self.mapContainer insertSubview:self.mapImage atIndex:0];
} break;
case UIGestureRecognizerStateChanged:
break;
default:
// Resize the map to the new dimension
self.map.frame = self.mapImage.frame;
// Replace the screenshot with the resized map
[self.mapImage removeFromSuperview];
[self.mapContainer insertSubview:self.map atIndex:0];
// Empty screenshot memory
self.mapImage = nil;
break;
}
// resize map container according do the translation value
CGRect mapFrame = self.mapContainer.frame;
mapFrame.size.height += translation.y;
// reset translation to make a relative read on next event
[sender setTranslation:CGPointZero inView:self.mapContainer];
self.mapContainer.frame = mapFrame;
self.map.centerCoordinate = centerCoordinate; // keep center
}