我正在開發顯示地圖的應用程序。我在地圖屬性中啓用了用戶當前位置,並且它現在顯示藍色點,表示用戶的當前位置,但現在我想啓用下圖左下角的按鈕(iPhone中地圖應用程序的快照)。ios:mapkit如何在地圖上啓用curent位置按鈕?
請告訴我,我怎麼得到這個在地圖上
我正在開發顯示地圖的應用程序。我在地圖屬性中啓用了用戶當前位置,並且它現在顯示藍色點,表示用戶的當前位置,但現在我想啓用下圖左下角的按鈕(iPhone中地圖應用程序的快照)。ios:mapkit如何在地圖上啓用curent位置按鈕?
請告訴我,我怎麼得到這個在地圖上
在這裏,你可以找到這個
繼實現的代碼,你可以找到在上面給出鏈接的圖像
//User Heading Button states images
UIImage *buttonImage = [UIImage imageNamed:@"greyButtonHighlight.png"];
UIImage *buttonImageHighlight = [UIImage imageNamed:@"greyButton.png"];
UIImage *buttonArrow = [UIImage imageNamed:@"LocationGrey.png"];
//Configure the button
userHeadingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[userHeadingBtn addTarget:self action:@selector(startShowingUserHeading:) forControlEvents:UIControlEventTouchUpInside];
//Add state images
[userHeadingBtn setBackgroundImage:buttonImage forState:UIControlStateNormal];
[userHeadingBtn setBackgroundImage:buttonImage forState:UIControlStateNormal];
[userHeadingBtn setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted];
[userHeadingBtn setImage:buttonArrow forState:UIControlStateNormal];
//Button shadow
userHeadingBtn.frame = CGRectMake(5,425,39,30);
userHeadingBtn.layer.cornerRadius = 8.0f;
userHeadingBtn.layer.masksToBounds = NO;
userHeadingBtn.layer.shadowColor = [UIColor blackColor].CGColor;
userHeadingBtn.layer.shadowOpacity = 0.8;
userHeadingBtn.layer.shadowRadius = 1;
userHeadingBtn.layer.shadowOffset = CGSizeMake(0, 1.0f);
[self.mapView addSubview:userHeadingBtn];
MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:mapView];
[trackButton setTarget:self];
[trackButton setAction:@selector(track:)];
[toolbar setItems:[NSArray arrayWithObjects:trackButton, nil] animated:YES];
您需要創建MKUserTrackingBarButtonItem並把它傳遞到的MKMapView無論你定義的MapView。類似下面:
- (void)viewDidLoad
{
[super viewDidLoad];
MKUserTrackingBarButtonItem *buttonItem = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.map];
self.navigationItem.rightBarButtonItem = buttonItem;
}
MKUserTrackingBarButtonItem是你需要的。嘗試在谷歌上搜索 – Pawan