Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jvpython

macrumors 6502
Original poster
Aug 25, 2011
284
0
New Zealand
I have a custom MKPinAnnotationView created as so:

Code:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
    if annotation is MKUserLocation {
        return nil
    }

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView

    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView!.canShowCallout = false
        pinView!.animatesDrop = true
        pinView!.pinColor = .Red
        pinView!.draggable = true;
    } else {
        pinView!.annotation = annotation
    }

    return pinView
}

Then I add a subview to it later with a button like this:

Code:
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
    view.addSubview(confirm)
}

The problem is that the button inside the subview is not responsive at all. What could be causing that? I already tried playing around with userInteraction enabled. Thanks
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
I have a custom MKPinAnnotationView created as so:

Code:
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
    if annotation is MKUserLocation {
        return nil
    }

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView

    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView!.canShowCallout = false
        pinView!.animatesDrop = true
        pinView!.pinColor = .Red
        pinView!.draggable = true;
    } else {
        pinView!.annotation = annotation
    }

    return pinView
}

Then I add a subview to it later with a button like this:

Code:
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
    view.addSubview(confirm)
}

The problem is that the button inside the subview is not responsive at all. What could be causing that? I already tried playing around with userInteraction enabled. Thanks

You've shared none of the code that creates the button so we can't help. You just add it as a subview.
 

jvpython

macrumors 6502
Original poster
Aug 25, 2011
284
0
New Zealand
You've shared none of the code that creates the button so we can't help. You just add it as a subview.

This is the subview code that creates the view + button:

Code:
let confirm = UIView(frame: CGRect(x: -30, y: -40, width: 205, height: 32))
confirm.backgroundColor = UIColor(white: 0.9, alpha: 1)
confirm.alpha = 0.7
		
let label = UILabel(frame: CGRectMake(9, 6, 150, 21))
label.text = "Go to this location?"
confirm.addSubview(label)
		
let button = UIButton.buttonWithType(UIButtonType.System) as UIButton
button.frame = CGRectMake(167, 2, 30, 30)
button.setTitle("Yes", forState: UIControlState.Normal)
button.addTarget(self, action: "confirmPressed:", forControlEvents: UIControlEvents.TouchUpInside)
confirm.addSubview(button)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.