-1

我在 viewController 的 scrollView 中实现了一个小的 mapView (65x65)。如果我为每个 XIB 设置 mapView 的位置并在模拟器或 iOS 设备上运行它,它不会位于正确的位置:

  • XIB 正确位置
  • iPhone 5 到高
  • iPhone 4(或模拟器)非常高

我可以使用这些代码纠正每种情况的位置,但这不是解决方案:

XIP 中相同位置的代码:

CGRect newFrameMapView = CGRectMake(10,171,65,65);
mapView.frame = newFrameMapView;

为 iPhone 5 上的输出更正它的代码:

CGRect newFrameMapView = CGRectMake(10,215,65,65);
mapView.frame = newFrameMapView;

为 iPhone 4 上的输出更正它的代码:

CGRect newFrameMapView = CGRectMake(10,302,65,65);
mapView.frame = newFrameMapView;

笔记:

  • 我在顶部有一个导航控制器。
  • 如果我将 mapView 放在 scrollView 之外,什么都不会改变。
  • 我不使用自动布局

--- 编辑 --- 23.01.2013 -----------------------------------

我已将“mapView”重命名为“mapView2”,以确保不会更改代码其他部分的位置。

以下是 .h 的重要代码片段

#import <MapKit/MapKit.h>

@interface ViewControllerDetail : UIViewController <MKMapViewDelegate> {

    IBOutlet MKMapView *mapView2;

}

@property(nonatomic, retain) IBOutlet MKMapView *mapView2;

@end

还有他们

@implementation ViewControllerDetail

@synthesize mapView2;

[...]

// Basic Settings Map

[mapView2 setMapType:MKMapTypeStandard];
[mapView2 setZoomEnabled:NO];
[mapView2 setScrollEnabled:NO];
[mapView2 setDelegate:self];

// Map Start

MKCoordinateRegion myStartRegion = { {0.0, 0.0}, {0.0, 0.0} };
myStartRegion.center.latitude = 44.087439;
myStartRegion.center.longitude = 2.139614;
myStartRegion.span.latitudeDelta = 0.003;
myStartRegion.span.longitudeDelta = 0.003;
[mapView2 setRegion:myStartRegion animated:NO];


// Map Point

MKCoordinateRegion myBeispielRegion = { {0.0, 0.0}, {0.0, 0.0} };
myRegion1.center.latitude = 44.087439;
myRegion1.center.longitude = 2.139614;
classAnnotation *annotationRegion1 = [[classAnnotation alloc] init];
annotationRegion1.coordinate = myRegion1.center;
[mapView2 addAnnotation:annotationRegion1];
4

1 回答 1

-1

我发现了错误:

(不知道这是否正常,我使用的是 Xcode 4.5 版)

如果我在 Xib 中插入 MapView,它会自动设置为 Autosizing left/bottom。我没有注意到,我认为标准的自动调整大小是左/上。

于 2013-02-05T10:03:40.790 回答