XIB和模拟器/ iOS设备中元素的不同位置

时间:2013-01-23 11:16:49

标签: objective-c xib

我在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之外,则没有任何变化。
  • 我不使用Autolayout

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

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

以下是.h

的重要代码片段
#import <MapKit/MapKit.h>

@interface ViewControllerDetail : UIViewController <MKMapViewDelegate> {

    IBOutlet MKMapView *mapView2;

}

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

@end

和.m

@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];

1 个答案:

答案 0 :(得分:-1)

我发现了错误:

(如果这是正常的Dunno,我使用Xcode版本4.5)

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