用UIButton作为子视图的MKannotationView,button不响应
我已经添加一个视图与button作为子视图MKAnnotationView
CCBigBubleViewController* buble = [[CCBigBubleViewController alloc] init]; [annotationView addSubView:buble.view];
它显示完美,但button不响应攻丝。
在你的MKAnnotationView实现中,重写hitTest方法:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { if (CGRectContainsPoint(_button.frame, point)) { return _button; } return [super hitTest:point withEvent:event]; }
您的button将会收到触摸事件。
你的annotationView可能不是正确的大小。 它的框架子视图不响应触摸。 为了testing这个,你可以剪辑到界限。
所以确保你的button是在你的AnnotationView的框架内,也许sizeToFit将在这里帮助。
您将不得不像这样在编码中创buildbutton操作
[buttonInstance addTarget:self action:@selector(youraction:) forControlEvents:UIControlEventTouchUpInside];
- 新手卡住:ASIHTTPRequest – 没有已知的类方法select器“requestWithURL”
- UISearchDisplayController不正确显示自定义单元格
- 尝试使用Grand Central Dispatch执行Realm事务时的RLMException
- 可以在Swift中拖拽UIButton / Elements?
- 关于iOS 5中的UIImagePickerController的api
- 没有NIB,UIWindow不填充屏幕,iOS 7
- self.view setNeedsDisplay和self.view setNeedsLayout无效
- 在Objective-C中使用枚举?
- 在Mapview Xcode中更新位置