自定义标注未接收触摸操作

时间:2015-09-09 05:54:20

标签: ios swift mapkit mkannotationview calloutview

func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
    /*
     * Other stuff ....
     */
    visibleCallOutView = CustomCallOut(frame: aFrame)
    view.addSubview(visibleCallOutView)
}

func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!) {
    visibleCallOutView.removeFromSuperview()
}

以下是自定义标注类

class CustomCallOut: UIView {
        override init(frame: CGRect) {
            super.init(frame: frame)

            let button = UIButton(frame: bounds)
            button.addTarget(self, action: "callOutButtonTouchAction:", forControlEvents: UIControlEvents.TouchUpInside)
            button.backgroundColor = UIColor.redColor()
            addSubview(button)
        }

        func callOutButtonTouchAction(sender: AnyObject) {
            println("callOutButtonTouchAction called")
        }

        required init(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }

        override func hitTest(var point: CGPoint, withEvent event: UIEvent?) -> UIView? {
            let viewPoint = superview?.convertPoint(point, toView: self) ?? point
            let isInsideView = pointInside(viewPoint, withEvent: event)
            var view = super.hitTest(viewPoint, withEvent: event)
            return view
        }

        override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
            return CGRectContainsPoint(bounds, point)
        }
    }

enter image description here

每件事都应该正常工作,但我无法接收红色按钮的触摸动作。任何建议都会很明显。

0 个答案:

没有答案