当我在地图下方创建故事板时,会占用整个屏幕。这是可以理解的,我用下面的代码来使用视图的整个边界。但是,如果我做一个正常的“初始化”,我会失去地图的功能!地图通常会放大我的位置和其他一些东西。当我使用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