nfarina / calloutview

A lightweight callout view class for iOS mimicking UICalloutView.
http://nfarina.com/post/78014139253/smcalloutview-for-ios-7
Apache License 2.0
1.2k stars 189 forks source link

Content View Touch - weird behaviour #109

Closed kkrawczynski closed 7 years ago

kkrawczynski commented 7 years ago

Hi,

thanks for nice library. I've reviewed example in repo and ive found weird issue that only occurs with SMCallout placed on Map -> the same code works fine on scroll view. Im not really sure what the problem is - i suspect something in mapkit itself is canceling touches which prevents tapping button

Sample Code (i put it in viewDidLoad as in repo's example):

UIButton* b = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[b addTarget:self action:@selector(tap:) forControlEvents:UIControlEventTouchUpInside];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[v addSubview:b];
self.calloutView.contentView= v;
self.calloutView.userInteractionEnabled = true;
self.calloutView.contentView.userInteractionEnabled = true;

PS.

Any help appreciated Cheers

kkrawczynski commented 7 years ago

i figured out that when you add callout to annotation view like [self.calloutView presentCalloutFromRect:annotationView.frame inView:annotationView constrainedToView:mapView animated:YES]; then it blocks interaction. Temporary solution is to add it into main view however you need to handle mapRegionChange as it doesnt move along with annotation

nfarina commented 7 years ago

You should be able to have user interaction with the callout even when presented from within an annotation view on an MKMapView. Check the sample code - there's an example callout on MKMapView that displays a button that should illustrate how to do it. You need to do some subclassing on the map view for touch interceptions to make it work.