繁体   English   中英

目标C:Route-Me代码在iPad模拟器4.2和5中的行为不同

[英]Objective C: Route-Me code behaves differently in iPad simulator 4.2 and 5

我试图同时使用Xcode iPad 4.2模拟器和iPad 5模拟器以及这两个模拟器来计算Route-Me代码发生的事情,并给出不同的结果。 这是代码片段:

    //set size of the map view
    [self setMapView:[[[RMMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024, 768)] autorelease]];
    [mapView setBackgroundColor:[UIColor blackColor]]; 
    self.view = mapView; 
    //set locked on default location of view, currently on conus
    CLLocationCoordinate2D newLocation;
    newLocation.latitude = 37.83;
    newLocation.longitude = -96.58;
    [[mapView contents] moveToLatLong:newLocation]; 
    [[mapView contents] setZoom:4.5];

然后在下面,我将应用程序设置为仅使用横向模式:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
         if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) { return YES; } return NO;
 }

我在Xcode的iPad Simulator 4.2中运行此代码,并得到下面看起来很完美的图像: 这里看起来不错

然后,我在Xcode的iPad Simulator 5上运行相同的代码,并得到以下奇怪的图像: 这很奇怪

我很困惑,难道他们不应该产生相同的结果吗? 还是我在这里想念东西?

编辑:我已经在我的plist文件中设置了初始界面方向和支持的界面方向以仅具有横向效果。

EDIT2:我尝试使用下面的代码按原样运行它,并且似乎可以正常工作,但是如果将setZoom行放入代码中,图片将再次被截断,请参见屏幕截图:

[self setMapView:[[RMMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024, 768)]];
[mapView setBackgroundColor:[UIColor grayColor]];
self.view = mapView;

在此处输入图片说明

一旦我添加了[mapView.contents setZoom:4.5]行,这真的变得很奇怪。 屏幕右侧缺少部分再次发生。

我已经弄清楚,似乎我无法假设我正在修改父视图的大小。 为了解决这个问题,我需要先将self.view分配给父控制器,然后再子视图mapView:

UIView* parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
parentView.autoresizesSubviews = YES;
self.view = parentView;

mapView = [[RMMapView alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024, 768)];
[parentView addSubview:mapView]; 

CLLocationCoordinate2D newLocation;
newLocation.latitude = 37.83;
newLocation.longitude = -96.58;
[mapView.contents moveToLatLong:newLocation];

[mapView setBackgroundColor:[UIColor grayColor]];
[mapView.contents setZoom:4.5];

在横向时,您需要反转宽度和高度。

RMMapView *baseMap = [[[RMMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width)] autorelease];

请记住,设备保留了相同的高度和宽度,您的矩形仅需针对已更改的方向进行更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM