本文介绍了MapView:使用MKUserTrackingBarButtonItem切换地图跟踪状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在工具栏中添加了MKUserTrackingBarButtonItem。但是,点击它什么都不做。所以,我假设我需要像普通的UIBarButtonItem一样使用 addTarget
,但这也不起作用。
I have added a MKUserTrackingBarButtonItem to my toolbar. But, clicking it does nothing. So, I assumed I need to use addTarget
like a normal UIBarButtonItem but that doesn't work either.
我可以将方法附加到该按钮,以便我可以更改 setUserTrackingMode:animated:
?
How can I attach a method to that button so that I can change setUserTrackingMode:animated:
?
MKUserTrackingBarButtonItem *trackingItem = [[[MKUserTrackingBarButtonItem alloc] initWithMapView:mapView] autorelease];
UISegmentedControl *segmentedControl = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"List", @"Detail", nil]] autorelease];
segmentedControl.frame = CGRectMake(0, 0, 220, 30);
[segmentedControl setWidth:100.0 forSegmentAtIndex:0];
[segmentedControl setWidth:100.0 forSegmentAtIndex:1];
[segmentedControl setSelectedSegmentIndex:0];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
UIBarButtonItem *segmentedButton = [[[UIBarButtonItem alloc] initWithCustomView:segmentedControl] autorelease];
UIBarButtonItem *pageCurl = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self action:nil] autorelease];
pageCurl.tintColor = [UIColor lightGrayColor];
UIBarButtonItem *leftFlex = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
UIBarButtonItem *rightFlex = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease];
self.toolbar.items = [NSArray arrayWithObjects:trackingItem, leftFlex, segmentedButton, rightFlex, pageCurl, nil];
推荐答案
MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:mapView];
[trackButton setTarget:self];
[trackButton setAction:@selector(track:)];
[toolbar setItems:[NSArray arrayWithObjects:trackButton, nil] animated:YES];
这篇关于MapView:使用MKUserTrackingBarButtonItem切换地图跟踪状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!