[英]Can't receive touch events from markerInfoWindow UIView in GMSMapView
我已經用XIB創建了一個自定義UIView,當用戶通過實現markerInfoWindow點擊一個標記時,會顯示該自定義UIView
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
TESTInfoWindow *view = [[[NSBundle mainBundle] loadNibNamed:@"TESTInfoWindow" owner:self options:nil] objectAtIndex:0];
view.lblTitle.text = [marker title];
return view;
}
一切正常,顯示我的XIB並填充標題。
我的問題是我無法獲得自定義UIView,TESTInfoWindow來響應觸摸事件。 (我希望用戶能夠拖動自定義信息窗口,並且應用程序將基於touchesEnd事件進行響應。)
我已經在TESTInfoWindow中實現了touchesBegan和touchesMoved,但都沒有被調用:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"DEBUG touchesBegan");
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"DEBUG touchesMoved");
}
我認為GMSMapView正在接收自定義信息窗口視圖忽略的觸摸。
如何獲取自定義UIView來接收觸摸? 任何幫助表示贊賞。
我只是通過此鏈接為您復制了答案, 在針對本地iOS /目標C的Google Maps SDK中的InfoWindow / Marker上添加Click Event
1.符合GMSMapViewDelegate協議。
@interface YourViewController () <GMSMapViewDelegate>
// your properties
@end
2.設置您的mapView_委托。
mapView_.delegate = self;
3,實現GMSMapViewDelegate方法
- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
// your code
NSNumber *number = [marker.userData objectForKey:@"marker_id"];
}
順便說一句, marker.userData
很有用。 您可以將所需的數據放入其中並在- mapView:didTapInfoWindowOfMarker:
使用它- mapView:didTapInfoWindowOfMarker:
例如在GMSMarker對象上設置userData
GMSMarker *marker = [[GMSMarker alloc] init];
marker.userData = @{@"marker_id":[NSNumber numberWithInt:12]};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.