當我在地圖下方創建故事板時,會佔用整個屏幕。這是可以理解的,我用下面的代碼來使用視圖的整個邊界。但是,如果我做一個正常的「初始化」,我會失去地圖的功能!地圖通常會放大我的位置和其他一些東西。當我使用init而不是initWithFrame時,地圖不會到達我的位置。MKMapView的錯誤
self.myMapView =[[MKMapView alloc]initWithFrame:self.view.bounds];
self.myMapView.delegate=self;
如何初始化地圖而不需要像我的故事板中顯示的那樣接管整個屏幕。 iOS新手,感謝您的幫助!
//Setting up the location manger for finding the User's location
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
//Check to see if they have Authorization to use to use location servieces
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
//Initialize the map and specifiy bounds
self.myMapView =[[MKMapView alloc]initWithFrame:self.view.bounds];
//Set the delegate to itself
self.myMapView.delegate=self;
//Set a standard mapview, Enable scrolling and zooming
self.myMapView.mapType = MKMapTypeStandard;
self.myMapView.scrollEnabled = YES;
self.myMapView.zoomEnabled = YES;
//specifcy resizing
self.myMapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
//show the User's location and set tracking mode
self.myMapView.showsUserLocation = YES;
self.myMapView.userTrackingMode = MKUserTrackingModeFollow;
//add the VIEW!!
[self.view addSubview:self.myMapView];
//Set up the UISearch Bar
self.mySearch = [[UISearchBar alloc]init];
self.mySearch.delegate = self;
//Set the initial Text
self.mySearch.prompt = @"Enter Address or Use Current Location";
你的問題不清楚。你想在故事板中添加地圖視圖還是在代碼中創建地圖視圖?你不應該這樣做。 – rdelmar 2014-11-04 01:18:12
原諒我我是iOS新手,我將MKMapView拖放到視圖控制器上,我相信它是在viewDidLoad方法的代碼中創建的。我已經添加了我的其他代碼。 – tennis779 2014-11-04 01:35:06
由於您已將它添加到故事板中的控制器,因此您不應該在代碼中創建一個。只需在故事板中設定想要的尺寸,併爲其添加適當的約束即可。 – rdelmar 2014-11-04 05:11:20