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

  • SEARCH
  • Home
  • 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 8290339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:46:59+00:00 2026-06-08T12:46:59+00:00

I am having some problems with changing an image view inside of an MKAnnotationView

  • 0

I am having some problems with changing an image view inside of an MKAnnotationView subclass. I have a timer that updates the annotation position based on data about where a user was at a certain point. This works fine and the annotation position is updated correctly. I do this with the following code:

[_myAnnotation setCoordinate:point.position];

Below this, I also calculate whether the user was heading east or west. If the user is heading east, I call the setIsMovingRight:YES method on the MyAnnotation class, and do the opposite for when the user is heading west.

I have verified that the method is being called with the correct values at the correct times by using NSLog inside the method to print out whenever the value changes. However, it doesn’t seem like the setIsMovingRight method has any effect on the visual appearance of the annotation. I try setting the background colour of the imageview to red whenever the method is called, but even this has no effect. I have tried calling setNeedsDisplay in various places with no success.

I can add and recreate an annotation view, but then the annotation flashes on and off whenever the position changes and it really does not look very good.

The following is the code for my custom annotation view, “MyAnnotation”.

@interface MyAnnotation : MKAnnotationView <MKAnnotation>
{
    UIImageView *_imageView;
    BOOL _currentlyMovingRight;
}

@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;

@property (nonatomic,retain) UIImage  *image;

-(void)setIsMovingRight:(BOOL)movingRight;

@end

@implementation MyAnnotation

@synthesize coordinate, title, subtitle, image;

-(id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if(self)
    {
        _currentlyMovingRight = NO;
        _imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
        [self addSubview:_imageView];
    }
    return self;
}

-(void)setIsMovingRight:(BOOL)movingRight
{
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [_imageView setBackgroundColor:[UIColor redColor]]; // THIS LINE NEVER DOES ANYTHING.

    if(movingRight && !_currentlyMovingRight)
    {
        NSLog(@"right now.");
        [_imageView setImage:[UIImage imageNamed:@"right.png"]];
    }
    else if (!movingRight && _currentlyMovingRight)
    {
        NSLog(@"left now.");
        [_imageView setImage:[UIImage imageNamed:@"left.png"]];
    }
    _currentlyMovingRight = movingRight;

    [self addSubview:_imageView];
    [self setNeedsDisplay];
}

I would appreciate any help or advice that anyone could give. Thanks!

  • 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-08T12:47:01+00:00Added an answer on June 8, 2026 at 12:47 pm

    I think that the annotation views use KVO to listen for changes. Have you tried changing the image property? Something like [self setImage:myNewImage]

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

Sidebar

Related Questions

I'm having some problems changing the DataTemplate that is used for a TreeViewItem when
I have a website with some areas that use https, however I'm having problems
I am having some problems with the PDF files that I make using the
I'm having some problems building an hierarchistic array structure - I have almost got
I'm having some problems with some commands in Java. I created a JAR that
I'm having some problems tracing the reason that I can't load a java(fx) applet.
Currently having some problems- now = datetime.datetime.now() month = now.strftime(%B) site = wikipedia.getSite('en', 'wikiquote')
Im having some problems getting the Sticky Footer to work on my site. If
Im having some problems with a simple toggle in Safari. A really annoying flickering
I'm having some problems trying to figure out how to generate a Google Map

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.