{"action":"created","issue":{"url":"https://api.github.com/repos/nfarina/calloutview/issues/62","repository_url":"https://api.github.com/repos/nfarina/calloutview","labels_url":"https://api.github.com/repos/nfarina/calloutview/issues/62/labels{/name}","comments_url":"https://api.github.com/repos/nfarina/calloutview/issues/62/comments","events_url":"https://api.github.com/repos/nfarina/calloutview/issues/62/events","html_url":"https://github.com/nfarina/calloutview/issues/62","id":33695541,"number":62,"title":"Touching custom contentView will close the calloutView","user":{"login":"guilhermearaujo","id":1733143,"avatar_url":"https://avatars.githubusercontent.com/u/1733143?v=3","gravatar_id":"","url":"https://api.github.com/users/guilhermearaujo","html_url":"https://github.com/guilhermearaujo","followers_url":"https://api.github.com/users/guilhermearaujo/followers","following_url":"https://api.github.com/users/guilhermearaujo/following{/other_user}","gists_url":"https://api.github.com/users/guilhermearaujo/gists{/gist_id}","starred_url":"https://api.github.com/users/guilhermearaujo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guilhermearaujo/subscriptions","organizations_url":"https://api.github.com/users/guilhermearaujo/orgs","repos_url":"https://api.github.com/users/guilhermearaujo/repos","events_url":"https://api.github.com/users/guilhermearaujo/events{/privacy}","received_events_url":"https://api.github.com/users/guilhermearaujo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2014-05-16T17:51:04Z","updated_at":"2016-09-07T16:40:04Z","closed_at":null,"body":"Using the \"standard\" view (with title + subtitle), if I tap the callout view, nothing will happen (or `calloutViewClicked` will be called, if the delegate is implemented).\r\nHowever if I set a custom `contentView` to my `calloutView` and then tap that custom view, the `calloutView` won't handle the touch. Instead, the map will dismiss it.\r\n\r\nHow can I avoid this behavior and prevent the callout view from hiding?"},"comment":{"url":"https://api.github.com/repos/nfarina/calloutview/issues/comments/245342066","html_url":"https://github.com/nfarina/calloutview/issues/62#issuecomment-245342066","issue_url":"https://api.github.com/repos/nfarina/calloutview/issues/62","id":245342066,"user":{"login":"jpm","id":29741,"avatar_url":"https://avatars.githubusercontent.com/u/29741?v=3","gravatar_id":"","url":"https://api.github.com/users/jpm","html_url":"https://github.com/jpm","followers_url":"https://api.github.com/users/jpm/followers","following_url":"https://api.github.com/users/jpm/following{/other_user}","gists_url":"https://api.github.com/users/jpm/gists{/gist_id}","starred_url":"https://api.github.com/users/jpm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpm/subscriptions","organizations_url":"https://api.github.com/users/jpm/orgs","repos_url":"https://api.github.com/users/jpm/repos","events_url":"https://api.github.com/users/jpm/events{/privacy}","received_events_url":"https://api.github.com/users/jpm/received_events","type":"User","site_admin":false},"created_at":"2016-09-07T16:40:04Z","updated_at":"2016-09-07T16:40:04Z","body":"Looks like every year we need another update on this ticket, so here's mine. :)\r\n\r\nI also reproduced this issue on my app. To be explicit, we are doing a custom `contentView` and the `calloutViewClicked:` delegate method would never fire. The custom `contentView` has a bunch of labels in it, plus a very small `UIButton`. Tapping anywhere on the callout would just dismiss it, and the delegate method never fired.\r\n\r\nWhat I did was expose the internal `containerView` property as readonly:\r\n\r\n```objc\r\n@property (nonatomic, strong, readonly) UIButton *containerView; // for masking and interaction\r\n```\r\n\r\nThen I modified the example `MKMapView` subclass:\r\n\r\n```objc\r\n// override UIGestureRecognizer's delegate method so we can prevent MKMapView's recognizer from firing\r\n// when we interact with UIControl subclasses inside our callout view.\r\n- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch\r\n{\r\n    if ([touch.view isKindOfClass:[UIControl class]])\r\n        return NO;\r\n    else\r\n        return [super gestureRecognizer:gestureRecognizer shouldReceiveTouch:touch];\r\n}\r\n\r\n// Allow touches to be sent to our calloutview.\r\n// See this for some discussion of why we need to override this: https://github.com/nfarina/calloutview/pull/9\r\n- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event\r\n{\r\n    UIView *calloutMaybe = [self.calloutView hitTest:[self.calloutView convertPoint:point fromView:self] withEvent:event];\r\n    if ([calloutMaybe isKindOfClass:[UIControl class]]) {\r\n        return calloutMaybe;\r\n    } else if (calloutMaybe) {\r\n        return self.calloutView.containerView;\r\n    }\r\n    \r\n    return [super hitTest:point withEvent:event];\r\n}\r\n```\r\n\r\nThis way if the hit test returns a UIControl subclass, then we pass the event on to it, otherwise we fall back to the main `UIButton` object which handles the callout taps (aka `containerView`).\r\n\r\n@nfarina Let me know if you would like me to provide a PR for it."}}
{"actor":{"display_login":"jpm"}}