2012-12-18 43 views
0

Button on the calloutView的UIButton不能點擊的註解

the structure of my calloutView

我遇到的問題對calloutView:我按一下按鈕,但似乎CalloutView收到代替的UIButton我點擊。

一些解釋第一:1。「SYSUMyAnnoCalloutView」是MKPinAnnotationView 2.「SYSUMyCalloutImageView」是一個UIImageView,我初始化它和addSubview對「SYSUMyAnnoCalloutView」 3. UIButton的和中的UILabel被addSubviewed了「 SYSUMyCalloutImageView」

相應的代碼: 1。在 「SYSUMyAnnoCalloutView.m」

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
if (selected){ 
    [self.calloutImageView setFrame:CGRectMake(-75, -100, 230, 130)]; 

    [self animateCalloutAppearance]; 
    //[self.calloutImageView becomeFirstResponder]; 
    //[self.calloutImageView.detailButton addTarget:self.calloutImageView action:@selector(clickForDetail) forControlEvents:UIControlEventTouchUpInside]; 
    [self addSubview:self.calloutImageView]; 
    [self setCanShowCallout:NO]; 
} 
else 
{ 
    //Remove your custom view... 
    [self.calloutImageView removeFromSuperview]; 
} 
} 
  • 在 「SYSUMyCalloutImageView.m」

    - (id)initWithImage:(UIImage *)image 
    { 
    self = [super initWithImage:image]; 
    if (self){ 
        //Label 
    CGRect boundsForLabel; 
    boundsForLabel.origin.x = 20; 
    boundsForLabel.origin.y = 50; 
    boundsForLabel.size.width = self.bounds.size.width - 100; 
    boundsForLabel.size.height = 20; 
    self.messageLabel = [[UILabel alloc] initWithFrame:boundsForLabel]; 
    self.messageLabel.backgroundColor = [UIColor clearColor]; 
    [self addSubview:self.messageLabel]; 
    //detailButton 
    CGRect buttonRect; 
    buttonRect.origin.x = 20; 
    buttonRect.origin.y = 80; 
    buttonRect.size.width = boundsForLabel.size.width-50; 
    buttonRect.size.height = 30; 
    self.detailButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [self.detailButton setFrame:buttonRect]; 
    [self.detailButton setTitle:@"Click for detail" forState:UIControlStateNormal]; 
    self.detailButton.userInteractionEnabled = YES; 
    //[self.detailButton addTarget:self.superview action:@selector(clickForDetail) forControlEvents:UIControlEventTouchUpInside]; 
    [self addSubview:self.detailButton]; 
    

    } return self; }

  • 有人可以解決我的問題嗎?將非常感謝:)

    回答

    1

    默認情況下,UIImageView不接受用戶交互。

    你應該嘗試加入這一行的代碼在你的SYSUMyCalloutImageView.m

    [self setUserInteractionEnabled:YES]; 
    
    +0

    感謝您的意見的initWithImage。 :) :) – JackieLam

    +1

    不要忘了點擊複選標記以將此答案設置爲您接受的答案:) – howanghk