MapView:使用 MKUserTrackingBarButtonItem 切换地图跟踪状态
我已将 MKUserTrackingBarButtonItem 添加到我的工具栏。但是,单击它没有任何作用。所以,我假设我需要像普通的 UIBarButtonItem 一样使用 addTarget
,但这也不起作用。
如何将方法附加到该按钮以便更改 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];
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.
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您应该使用此方法初始化 MKUserTrackingBarButtonItem:
请参阅文档: http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKUserTrackingBarButtonItemClassRef/Reference/Reference.html
I think you should initialize the MKUserTrackingBarButtonItem with this method:
Refer to the documentation: http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKUserTrackingBarButtonItemClassRef/Reference/Reference.html