ios - 为什么 calloutAccessoryControlTapped 也会在注释 View 上被调用?

标签 ios swift mapkit

我的 View Controller 上有一张 map ,我不知道为什么,但是当我点击注释 View 时,委托(delegate) calloutAccessoryControlTapped 也会被调用,而不仅仅是当我点击细节时关闭。那么为什么会出现这种行为呢?

import UIKit
import MapKit

extension MapVC: MKMapViewDelegate, CLLocationManagerDelegate
{    
    func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl)
    {
        ...
    }

}

最佳答案

根据 Apple 开发者文档:

Accessory views contain custom content and are positioned on either side of the annotation title text. If a view you specify is a descendant of the UIControl class, the map view calls this method as a convenience whenever the user taps your view. You can use this method to respond to taps and perform any actions associated with that control. For example, if your control displayed additional information about the annotation, you could use this method to present a modal panel with that information.

If your custom accessory views are not descendants of the UIControl class, the map view does not call this method.

那么你的accessory view是继承自UIControl的吗?

引用: https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/#//apple_ref/occ/intfm/MKMapViewDelegate/mapView:annotationView:calloutAccessoryControlTapped :

关于ios - 为什么 calloutAccessoryControlTapped 也会在注释 View 上被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36432782/

相关文章:

javascript - 解析 iOS、云代码和后台作业

ios - 带有动态部分的 Swift 静态表格 View

ios - 使用 NSFetchedResultsController 的 UITableView 部分出现意外的标题 View

ios - 在 MapKit 中沿弧线对视觉元素进行动画处理

swift - 如何按字母顺序对注释数组进行排序

ios - 将 MapKit 注释连接到 TableView

ios - 从解析列中获取值到标签中

Swift 类作为 objc 运行时的参数

arrays - 如何更新 Swift 中数组中包含的值?

iphone - "EXC_BAD_ACCESS"当在 tableView 和 mapView 之间切换太快时