异步加载MKMapView?
当我第一次打开 MKMapView 时,我的应用程序在加载时似乎暂停了。我假设这是因为它不异步加载。
有什么办法可以解决这个问题吗?当它加载时,您无法切换选项卡或执行任何操作。
谢谢
编辑:这是我的 viewDidLoad 方法:
CGRect bounds = self.view.bounds;
mapView = [[MKMapView alloc] initWithFrame:bounds];
mapView.mapType=MKMapTypeStandard;
mapView.showsUserLocation = YES;
mapView.delegate = self;
[self.view insertSubview:mapView atIndex:0];
NSArray *mapTypes = [NSArray arrayWithObjects:@"Standard",@"Satellite",@"Hybrid",nil];
mapType = [[UISegmentedControl alloc] initWithItems:mapTypes];
[mapType setSegmentedControlStyle:UISegmentedControlStyleBar];
[mapType setCenter:CGPointMake(210, 345)];
[mapType setSelectedSegmentIndex:0];
[mapType setTintColor:[UIColor darkGrayColor]];
[mapType addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mapType];
// refresh button...
UISegmentedControl *refreshButton = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Refresh",nil]] autorelease];
[refreshButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[refreshButton setCenter:CGPointMake(self.view.frame.size.width-((refreshButton.frame.size.width/2)+5),(refreshButton.frame.size.height/2)+5)];
[refreshButton setMomentary:YES];
[refreshButton setTintColor:[UIColor darkGrayColor]];
[refreshButton addTarget:self action:@selector(updateMarkers) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:refreshButton];
UIBarButtonItem *leftBarButton = [[[UIBarButtonItem alloc] initWithTitle:@"List" style:UIBarButtonItemStylePlain target:self action:@selector(goToList)] autorelease];
[self.navigationItem setRightBarButtonItem:leftBarButton animated:YES];
// refresh label
refreshView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, self.view.frame.size.width-74, 40)];
[refreshView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.8]];
[refreshView.layer setCornerRadius:5];
[self.view addSubview:refreshView];
UILabel *refreshLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5, 5, refreshView.frame.size.width-10, refreshView.frame.size.height-10)] autorelease];
[refreshLabel setTextColor:[UIColor whiteColor]];
[refreshLabel setBackgroundColor:[UIColor clearColor]];
[refreshLabel setFont:[UIFont fontWithName:@"Helvetica" size:12]];
[refreshLabel setNumberOfLines:2];
[refreshLabel setLineBreakMode:UILineBreakModeWordWrap];
[refreshLabel setText:@"Move the map and press 'refresh' to load new results."];
[refreshView addSubview:refreshLabel];
[NSTimer scheduledTimerWithTimeInterval:10 target:refreshView selector:@selector(removeFromSuperview) userInfo:nil repeats:NO];
When I first bring up an MKMapView my app seems to pause while it loads. I am assuming this is because it doesn't load asynchronously.
Is there any way I can get around this. While it loads you can't switch tabs or do anything.
Thanks
EDIT: here is my viewDidLoad
method:
CGRect bounds = self.view.bounds;
mapView = [[MKMapView alloc] initWithFrame:bounds];
mapView.mapType=MKMapTypeStandard;
mapView.showsUserLocation = YES;
mapView.delegate = self;
[self.view insertSubview:mapView atIndex:0];
NSArray *mapTypes = [NSArray arrayWithObjects:@"Standard",@"Satellite",@"Hybrid",nil];
mapType = [[UISegmentedControl alloc] initWithItems:mapTypes];
[mapType setSegmentedControlStyle:UISegmentedControlStyleBar];
[mapType setCenter:CGPointMake(210, 345)];
[mapType setSelectedSegmentIndex:0];
[mapType setTintColor:[UIColor darkGrayColor]];
[mapType addTarget:self action:@selector(changeType:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mapType];
// refresh button...
UISegmentedControl *refreshButton = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Refresh",nil]] autorelease];
[refreshButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[refreshButton setCenter:CGPointMake(self.view.frame.size.width-((refreshButton.frame.size.width/2)+5),(refreshButton.frame.size.height/2)+5)];
[refreshButton setMomentary:YES];
[refreshButton setTintColor:[UIColor darkGrayColor]];
[refreshButton addTarget:self action:@selector(updateMarkers) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:refreshButton];
UIBarButtonItem *leftBarButton = [[[UIBarButtonItem alloc] initWithTitle:@"List" style:UIBarButtonItemStylePlain target:self action:@selector(goToList)] autorelease];
[self.navigationItem setRightBarButtonItem:leftBarButton animated:YES];
// refresh label
refreshView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, self.view.frame.size.width-74, 40)];
[refreshView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.8]];
[refreshView.layer setCornerRadius:5];
[self.view addSubview:refreshView];
UILabel *refreshLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5, 5, refreshView.frame.size.width-10, refreshView.frame.size.height-10)] autorelease];
[refreshLabel setTextColor:[UIColor whiteColor]];
[refreshLabel setBackgroundColor:[UIColor clearColor]];
[refreshLabel setFont:[UIFont fontWithName:@"Helvetica" size:12]];
[refreshLabel setNumberOfLines:2];
[refreshLabel setLineBreakMode:UILineBreakModeWordWrap];
[refreshLabel setText:@"Move the map and press 'refresh' to load new results."];
[refreshView addSubview:refreshLabel];
[NSTimer scheduledTimerWithTimeInterval:10 target:refreshView selector:@selector(removeFromSuperview) userInfo:nil repeats:NO];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论