ios - 如何在 MapView 注释中将右访问器的框架调整到右上角?

标签 ios xcode dictionary mkmapview mkpinannotationview

我想在右上角添加正确的访问器图像(十字图像),如下图所示,但我无法获得它的代码: 我正在使用以下代码,但它没有给我我需要的东西。我需要下图所示位置的十字按钮。

annView.leftCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd];

       UIImage *listImage = [UIImage imageNamed:@"Close_normal.png"];
       UIButton *listButton = [UIButton buttonWithType:UIButtonTypeCustom];

       // get the image size and apply it to the button frame
      // listButton.frame = CGRectMake(0,0,56,68);

       CGRect listButtonFrame = listButton.frame;


    listButtonFrame.size = listImage.size;
       listButton.frame = listButtonFrame;

       [listButton setImage:listImage forState:UIControlStateNormal];

   annView.rightCalloutAccessoryView = listButton;

enter image description here

然后我还需要做的是,当我点击十字按钮时,它应该关闭信息弹出窗口并删除注释

- (void) mapView:(MKMapView *)mv annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
 {
if( // left accessor is clicked then execute this code)  // what should i write here
 {
 SiteAnnotation *site = (SiteAnnotation *)view.annotation;
  if(site.category == -1) {
   if(addressAnnotation) {
       [mapView removeAnnotation:addressAnnotation];
AddViewController *vc = [[[AddViewController alloc]        initWithCoordinate:addressAnnotation.coordinate] autorelease];


   [self.delegate pushViewController:vc animated:YES];

   }
 }
        else {
             [self showSiteDetails:site.identifier];
             }
}
 else if (// if right accessor cross image is clicked)
{
  // Then here the code to dismiss the pop up and annotation pin on map

}
}

最佳答案

你可以检查这段代码:

在上面的方法和控制标签中使用标签让标签在下面工作..

 annView.leftCalloutAccessoryView.tag=1;
        annView.rightCalloutAccessoryView.tag=2;



- (void) mapView:(MKMapView *)mv annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    SiteAnnotation *site = (SiteAnnotation *)view.annotation;


    // Left Accessory Button Tapped

    if(site.category == -1) {


        if ([control tag] == 1) {


            if(addressAnnotation) {

so on...
}

下次试试

else if ([control tag] == 2) {

            // "Right Accessory Button Tapped


            UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"" message:@"Touch and hold the pin icon to drag it around." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Done", nil];
            [alert1 show];
            [alert1 release];
        }

然后在方法中

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

 UIAlertView *alert_pin = [[UIAlertView alloc] initWithTitle:@"" message:@"cancel button click it " delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Done", nil];

                [alert_pin show];
                [alert_pin release];

                [mapView removeAnnotation:addressAnnotation];
                [addressAnnotation release];
                addressAnnotation = nil;

            }

使用警报并要求用户关闭它,而不是仅在标注上使用直接关闭按钮。

关于ios - 如何在 MapView 注释中将右访问器的框架调整到右上角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14228701/

相关文章:

ios - 使用 FacebookSDK 从异步 block 返回值的方法

ios - 在我的案例中,我需要 iPhone/iPad 特定的按钮图像吗?

python - 按值获取键,字典,python

excel - 防止循环更新所有子字典值

iphone - iOS 如何决定向哪些对象发送 didReceiveMemoryWarning 消息?

iphone - 如何在一个 TextView 中显示字符串的某些部分并在其他 TextView 中扩孔

ios - TEMP FIX - 构建并上传 iOS 应用程序 Expo(没有应用程序加载器)

将应用分发到应用商店时 Xcode 崩溃

ios - 为什么这些 UITextView 中的背景不清晰?

python - 字典列表中的单个列表