Reputation: 668
The problem I encountered: I click on the button, but it seems that the CalloutView received my clicking instead of the UIButton.
Some explanation first: 1.the "SYSUMyAnnoCalloutView" is a MKPinAnnotationView 2.the "SYSUMyCalloutImageView" is a UIImageView, which I init it and addSubview on the "SYSUMyAnnoCalloutView" 3. the UIButton and the UILabel was addSubviewed in the "SYSUMyCalloutImageView"
Corresponding code: 1. In the "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];
}
}
In the "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; }
could anybody solve my problem?? will be really appreciate that:)
Upvotes: 0
Views: 97
Reputation: 3090
by default an UIImageView do not accept user interactions.
You should try adding this line of code in the initWithImage
of your SYSUMyCalloutImageView.m
[self setUserInteractionEnabled:YES];
Upvotes: 1