私が遭遇した問題: ボタンをクリックしましたが、UIButton ではなく CalloutView がクリックを受け取ったようです。
最初にいくつかの説明: 1.「SYSUMyAnnoCalloutView」は MKPinAnnotationView です 2.「SYSUMyCalloutImageView」は UIImageView です。これを初期化し、「SYSUMyAnnoCalloutView」に Subview を追加します
対応コード: 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];
自己を返します。}
誰でも私の問題を解決できますか?? 本当に感謝します:)