1)我有ViewController和MapKit
1.1)我在Map中添加了一些引脚
class ViewController: UIViewController, MKMapViewDelegate2)我为自定义引脚标注和注释编写了新的类
class CustomPointAnnotation: MKPointAnnotation {
class CustomCalloutView: UIView {3)我为我的自定义引脚标注创建了.xib

4)我在我的.xib中创建了按钮,这个按钮必须做一些事情,例如
@IBAction func clickTest(sender: AnyObject) {
print("aaaaa")
}5)这个按钮不工作
这方面的做法通常是什么?我想让我的按钮正常工作。按钮是蓝色的:

所有你能看到的https://github.com/genFollowMe1/forStack项目:谢谢,抱歉,英语)
发布于 2016-04-08 13:28:13
目标C的: https://github.com/nfarina/calloutview
更新
斯威普
子类MKAnnotationView,用于自定义调用和重写hitTest:和pointInside:方法。
import UIKit
import MapKit
class CustomCalloutView: MKAnnotationView {
@IBOutlet weak var name: UILabel!
@IBAction func goButton(sender: AnyObject) {
print("button clicked sucessfully")
}
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
let hitView = super.hitTest(point, withEvent: event)
if hitView != nil {
superview?.bringSubviewToFront(self)
}
return hitView
}
override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
let rect = self.bounds
var isInside = CGRectContainsPoint(rect, point)
if !isInside {
for view in subviews {
isInside = CGRectContainsPoint(view.frame, point)
if isInside {
break
}
}
}
return isInside
}
}发布于 2016-04-08 12:58:46
您必须做的方法是将按钮从.xib引用到关联的.swift文件中。
在您的ViewController中,您可以这样做:
let button:UIButton!
[...]
button.targetForAction("tappedButton:", withSender: self)
func tappedButton() {
print("Taped !")
}https://stackoverflow.com/questions/36499455
复制相似问题