Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8835995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:23:26+00:00 2026-06-14T09:23:26+00:00

I’ve been strunggling with an issue on my project : I’ve a mapView and

  • 0

I’ve been strunggling with an issue on my project :

I’ve a mapView and I have to show the annotation presented below (The small (+) is my button)

what's I have to do

I’ve subclassed MKAnnotationView and I have CustomAnnotationView.h like this :

@interface CustomAnnotationView : MKAnnotationView

@property (strong, nonatomic) UIImageView *calloutView;
@property (strong, nonatomic) UIButton *pinButton;
@property (strong, nonatomic) UIView *annView;

- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
- (void)animateCalloutAppearance;

My CustomAnnotationView.m

- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];


    if(selected)
    {
        //building my custom animation 
        annView = [[ UIView alloc ] initWithFrame:(CGRectMake(0, 0, 30, 30)) ];

        annView.frame =CGRectMake(0, 0, 200, 50);

        calloutView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"customcallout.png"]];


        [calloutView setFrame:CGRectMake(-25, 50, 0, 0)];
        [calloutView sizeToFit];


        [self animateCalloutAppearance];

        //I tried to add a button here but I could't do it like it should be
        [annView addSubview:calloutView];

        [self addSubview:annView];

    }
    else
    {
        //Remove your custom view...

        [annView removeFromSuperview];
    }
}

- (void)didAddSubview:(UIView *)subview{


        if ([[[subview class] description] isEqualToString:@"UICalloutView"]) {
            for (UIView *subsubView in subview.subviews) {
                if ([subsubView class] == [UIImageView class]) {
                    UIImageView *imageView = ((UIImageView *)subsubView);
                    [imageView removeFromSuperview];
                }else if ([subsubView class] == [UILabel class]) {
                    UILabel *labelView = ((UILabel *)subsubView);
                    [labelView removeFromSuperview];
                }
            }

    }
}


- (void)animateCalloutAppearance {
    CGFloat scale = 0.001f;
    calloutView.transform = CGAffineTransformMake(scale, 0.0f, 0.0f, scale, 0, -50);

    [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationCurveEaseOut animations:^{
        CGFloat scale = 1.1f;
        calloutView.transform = CGAffineTransformMake(scale, 0.0f, 0.0f, scale, 0, 2);

    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.1 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
            CGFloat scale = 0.95;
            calloutView.transform = CGAffineTransformMake(scale, 0.0f, 0.0f, scale, 0, -2);

        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.075 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
                CGFloat scale = 1.0;
                calloutView.transform = CGAffineTransformMake(scale, 0.0f, 0.0f, scale, 0, 0);

            } completion:nil];
        }];
    }];
}

@end

With this I’m able to show my custom annotation on the map but I can’t figure out how to place a button on it and this button should of course be able to respond to clicks like the callback calloutAccessoryControlTapped:

Please anyone with a working example code or idea.
Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:23:27+00:00Added an answer on June 14, 2026 at 9:23 am

    I solved this using - (UIView*)hitTest in my CustmAnnotationView.m class. I have a separate nib for the callout view and use hittest to determine whether the UILabel named directionsButton (linked from the callout nib) was clicked:

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
    {
        if (selected) {
            calloutVisible = YES;
            hitTestBuffer = NO;
            self.calloutView = [[[NSBundle mainBundle] loadNibNamed:@"CalloutView" owner:self options:nil] objectAtIndex:0];  
            [directionsButton setFont:[UIFont fontWithName:@"DIN-Medium" size:12.0f]];
            [calloutView setFrame:CGRectMake(calloutView.frame.origin.x, calloutView.frame.origin.y, 280, calloutView.frame.size.height)];          
            [calloutView setAlpha:0.0f];    
            [self addSubview:calloutView];
            [self sendSubviewToBack:calloutView];
    
    
            [UIView animateWithDuration:0.3f delay:0.0f options:0 animations:^{     
                [calloutView setAlpha:1.0f];
            } completion:^(BOOL finished) {
            }];
    
            [super setSelected:selected animated:animated];
    
        } else {
            calloutVisible = NO;
    
            CGRect newFrame = self.frame;
            newFrame.size.width = 52;
            self.frame = newFrame;
    
            [UIView animateWithDuration:0.3f delay:0.0f options:0 animations:^{
                [calloutView setAlpha:0.0f];
            } completion:^(BOOL finished) {
                [calloutView removeFromSuperview];
            }];
        }
    }
    
    
    - (void)directionsPressed
    {
        if ([parent respondsToSelector:@selector(directionsPressed:)])
            [parent performSelector:@selector(directionsPressed:) withObject:self.stockist];
    }
    
    
    - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
    {
        if (calloutVisible) {
            CGPoint hitPoint = [calloutView convertPoint:point toView:directionsButton];
            if ([calloutView pointInside:hitPoint withEvent:event]) {
                if (!hitTestBuffer) {
                    [self directionsPressed];
                    hitTestBuffer = YES;
                }
                return [directionsButton hitTest:point withEvent:event];
            } else {
                hitTestBuffer = NO;
            }
        }
        return [super hitTest:point withEvent:event];
    }
    

    In my code parent is my current VC. This is probably not the neatest way but it worked at the time.

    The callout looks like this:

    callout

    A couple of booleans calloutVisible and hitTestBuffer make sure the button is only clickable once and only when visible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have been unable to fix a problem with Java Unicode and encoding. The
I have a small JavaScript validation script that validates inputs based on Regex. I
I have an array which has BIG numbers and small numbers in it. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.