【发布时间】:2014-02-24 11:31:12
【问题描述】:
我为我的地图视图创建了自定义注释和标注。当用户单击标注视图或单击添加为标注视图的子视图的按钮时,我需要导航到另一个视图。但是在这种情况下,手势识别器和添加目标都不适合我。 setSelected: 方法被调用,当在调用视图中点击时视图被隐藏。
@interface VBPunchCardAnnotation : MKAnnotationView{
UIView *calloutView;
}
- (id)initWithAnnotation:(id )annotation reuseIdentifier:(NSString *)reuseIdentifier deal:(id)punchdeal
{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
calloutView = [[UIView alloc] init];
calloutView.hidden = YES;
infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[calloutView addSubview:infoButton];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(annotationTapped:)];
singleTap.numberOfTapsRequired = 1;
singleTap.delegate = self;
[calloutView addGestureRecognizer:singleTap];
[infoButton addTarget:self action:@selector(annotationTapped:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:calloutView];
return self;
}
-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{
// show/hide callout and swap pin image
calloutView.hidden = !selected;
self.image = !selected ? normalPin : selectedPin;
// dispatch an event to alert app a pin has been selected
if(selected) [[NSNotificationCenter defaultCenter] postNotificationName:@"punchCardAnnotation" object:self];
}
-(void)annotationTapped:(id)sender{
[self.delegate punchCardAnnotationClickedForDeal:self.punchDeal];
}
【问题讨论】:
-
你在设置 calloutView.frame 和 infoButton.frame 吗?
-
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
-
@Anna 是的。我正在设置信息按钮的框架并将标注视图添加为 [self addSubview:calloutView];
标签: ios objective-c mkmapview mkannotation mkannotationview