Loading MKMapView asynchronously?

杀马特。学长 韩版系。学妹 提交于 2019-12-07 22:42:54

问题


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];

来源:https://stackoverflow.com/questions/3969589/loading-mkmapview-asynchronously

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!