我已經爲我的地圖視圖創建了自定義註釋和調用。當用戶點擊呼出視圖時,我需要導航到另一個視圖,或者他點擊了作爲子視圖添加到標註視圖的按鈕。但在這種情況下,手勢識別器和添加目標都不適用於我。 setSelected:方法被調用,並且在調出視圖中出現敲擊時視圖將隱藏。未獲取按鈕動作/單擊自定義MKannotation召喚視圖
@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嗎? – Anna
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event –
@Anna是的。我設置信息按鈕框架並添加標註視圖爲[self addSubview:calloutView]; – iGo