2014-02-24 21 views
2

我已經爲我的地圖視圖創建了自定義註釋和調用。當用戶點擊呼出視圖時,我需要導航到另一個視圖,或者他點擊了作爲子視圖添加到標註視圖的按鈕。但在這種情況下,手勢識別器和添加目標都不適用於我。 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]; 
} 
+0

你在設置calloutView.frame和infoButton.frame嗎? – Anna

+1

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event –

+0

@Anna是的。我設置信息按鈕框架並添加標註視圖爲[self addSubview:calloutView]; – iGo

回答

0
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event 
{ 
    UIView* hitView = [super hitTest:point withEvent:event]; 
    if ([hitView isKindOfClass:[UIButton class]]) { 

    } 
} 
+0

未進入狀態。還檢查了條件if([hitView isKindOfClass:[calloutView class]])...但是當用戶單擊註釋引腳時會調用該條件。不是當通話視圖點擊時! – iGo

+0

NSLog(@「%@」,hitView); –

+0

單擊註釋時,將顯示調出視圖並記錄視圖名稱。但是,當調出視圖被點擊時,它完全消失,但日誌打印(空) – iGo