2013-05-19 26 views
1

我创建一个标签栏应用程序与故事板。iOS的地图视图自动布局问题

基本上在SecondViewController,我设立的MKMapView与工具栏在顶部用于改变视图等

我设置跨度和添加的注释被加载的画面时,显示,它正确地示出了当向上使用自动版式:关如下图所示

(抱歉,我不能嵌入的链接,即时通讯新这里)

http://img211.imageshack.us/img211/9359/mvautooff1.jpg

当我把自动版式,以在它这样做

http://img153.imageshack.us/img153/3736/mvautoon.jpg

我试图改变跨度等,并运行模拟器时,没有什么变化。

我能怎样改变这样的MapView显示像它自动版式时是关闭的?

是否有人可以帮助我,因为我喜欢的自动版式要作为调整大小的设备等,但我需要的MapView显示它如何做自动版式时是关闭的。

我很新到iOS编码和我完全对于新手

任何帮助将不胜感激!

感谢

的.M的代码 -

#import "SecondViewController.h" 
#import "Annotation.h" 

@interface SecondViewController() 

@end 

//Coordinates of Salon 
#define SALON_LATITUDE -33.427528; 
#define SALON_LONGITUDE 151.341697; 

//Span 
#define THE_SPAN 0.005f; 

@implementation SecondViewController 
@synthesize myMapView; 

//Find my location button 
-(IBAction)findmylocation:(id)sender { 

myMapView.showsUserLocation = YES; 
myMapView.delegate = self; 
[myMapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES]; 
} 

//Set map type button 
-(IBAction)setmaptype:(id)sender { 

switch (((UISegmentedControl *)sender).selectedSegmentIndex) { 

    case 0: 
     myMapView.mapType = MKMapTypeStandard; 
     break; 
    case 1: 
     myMapView.mapType = MKMapTypeHybrid; 
     break; 
    case 2: 
     myMapView.mapType = MKMapTypeSatellite; 
     break; 

    default: 
     myMapView.mapType = MKMapTypeStandard; 
     break; 
} 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

//Create the region 
MKCoordinateRegion myRegion; 

//Center 
CLLocationCoordinate2D center; 
center.latitude = SALON_LATITUDE; 
center.longitude = SALON_LONGITUDE; 

//Span 
MKCoordinateSpan span; 
span.latitudeDelta = THE_SPAN; 
span.longitudeDelta = THE_SPAN; 

myRegion.center = center; 
myRegion.span = span; 

//Set our mapView 
[myMapView setRegion:myRegion animated:YES]; 


//Annotation 

//1. Create a coordinate for use with the annotation 
CLLocationCoordinate2D salonLocation; 
salonLocation.latitude = SALON_LATITUDE; 
salonLocation.longitude = SALON_LONGITUDE; 


Annotation * myAnnotation = [Annotation alloc]; 
myAnnotation.coordinate = salonLocation; 
myAnnotation.title = @"Generic Haircuts"; 
myAnnotation.subtitle = @"8888 Mann St, Gosford, 2250"; 

[self.myMapView addAnnotation:myAnnotation]; 

//Automatic annotation - CUSTOM CODE 
[self.myMapView selectAnnotation:myAnnotation animated:YES]; 

} 
- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

@end 
+0

我可以看到您发布的第二张图片,但不是第1张图片。当自动布局关闭时,您可以再次上传屏幕截图吗? –

+0

我刚刚重新上传了你正在谈论的图片,谢谢你 –

+0

我不确定地图加载时会发生什么。你还可以发布你的地图视图控制器的代码吗?当自动布局开启和关闭时,IB的屏幕截图也会有所帮助。 –

回答

2

尝试调用setRegion方法viewDidAppear从viewDidLoad中删除:用自动布局基本上

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 

    //Create the region 
    MKCoordinateRegion myRegion; 

    //Center 
    CLLocationCoordinate2D center; 
    center.latitude = SALON_LATITUDE; 
    center.longitude = SALON_LONGITUDE; 

    //Span 
    MKCoordinateSpan span; 
    span.latitudeDelta = THE_SPAN; 
    span.longitudeDelta = THE_SPAN; 

    myRegion.center = center; 
    myRegion.span = span; 

    //Set our mapView 
    [self.myMapView setRegion:myRegion animated:YES]; 
} 

,地图视图的帧不是在viewDidLoad中还设置:

iOS AutoLayout - get frame size width

因此,setRegion无法正常工作。

MKMapView : setRegion doesn't work !

+0

非常感谢你!!! 你已经挽救了我的大脑很多挫折! –

+0

@SeanMcQuarrie:不客气: )。如果需要,您可以从保管箱中删除代码。 –