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 8391669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:19:20+00:00 2026-06-09T19:19:20+00:00

I’m trying to have a custom MKAnnotationView (PostFlag) do two things when it is

  • 0

I’m trying to have a custom MKAnnotationView (PostFlag) do two things when it is selected: 1) expand to show details about the annotation, and 2) become centered in the map. The trouble is that when the annotation is selected, the MKMapView sometimes dramatically zooms out. This causes my logic for handling significant zoom events to run, which collects nearby annotations into common annotation views, causing the annotation views to reload, which often replaces the annotation the user was trying to view with a closed annotation view.

My attempts to fix this started by trying to be sure that I don’t set the region incorrectly (with a span that would cause the zoom-out for example) when I try to center the annotation. Everything there seems ok – the region is correct when I set it. The delegate method mapView:didChangeRegion:animated: still gets called though with a zoomed out region. I’m not sure exactly what’s going on there.

Setting scrollEnabled and zoomEnabled to NO before changing the region to center the annotation doesn’t seem to have any effect.

It doesn’t matter if I animate the expansion of the annotation view or not – the zooming still occurs.

Does this sound familiar to anyone? Here’s some code:

- (void) mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    self.selectedFlag = (PostFlag*)view;  //disables scrolling/zooming on the map

    //move region to show expanded flag
    float size = (m_selectedFlag.expandedHeight / 2.0) + 50; //getting a comfortable position in the display
    float dLat = size * mapView.region.span.latitudeDelta / mapView.frame.size.height;  //get span in degrees from degree to pixel ratio

    //build a new coordinate for our center location
    CLLocationCoordinate2D originalCoord = ((PostAnnotation*)m_selectedFlag.annotation).coordinate;
    CLLocationCoordinate2D offsetCoord = CLLocationCoordinate2DMake(originalCoord.latitude + dLat, originalCoord.longitude);

    //adjust the map view to center on that new coordinate
    [m_mapView setRegion: MKCoordinateRegionMake(offsetCoord, m_mapRegionAtTimeOfLastUpdate.span) animated: YES];
}


- (void) setSelectedFlag:(PostFlag *) val
{
    if(m_selectedFlag)
    {
        m_selectedFlag.expanded = NO;
        [m_selectedFlag release];
    }

    if(val)
        m_selectedFlag = [val retain];
    else
        m_selectedFlag = nil;

    if(m_selectedFlag)
    {
        m_selectedFlag.expanded = YES;

        [m_mapView bringSubviewToFront: m_selectedFlag];
        m_mapView.scrollEnabled = NO;
        m_mapView.zoomEnabled = NO;
    }
    else
    {
        m_mapView.scrollEnabled = YES;
        m_mapView.zoomEnabled = YES;
    }
}

When a PostFlag collapses, it tells this view controller and the vc re-enabled scrolling and zooming on the map. So, just to be clear, while the annotation view is expanded, the zoom and scroll on the map are turned off.

- (void) postFlagWasCollapsed: (PostFlag*) flag
{
    [self.expandedFlags removeObject: flag];

    if([self.expandedFlags count] == 0)
    {
        m_mapView.scrollEnabled = YES;
        m_mapView.zoomEnabled = YES;
    }
}

Also, just to clarify, I’m keeping an array of what annotation views are expanded. Since the user can tap a nearby annotation view and expand it while the previously expanded one closes, there may be a lapse where two annotation views are expanded simultaneously. Therefor, to be sure I don’t turn the scrolling/zooming back on until all annotations are closed, I use the array.

- (void) postFlagWasExpanded: (PostFlag*) flag
{
    if(!self.expandedFlags)
        self.expandedFlags = [NSMutableArray array];

    if([self.expandedFlags indexOfObject: flag] == NSNotFound)
        [self.expandedFlags addObject: flag];

}

So that’s probably more details than you wanted. But if anyone has any idea as to why the map view is zooming out when annotation views are selected, please chime in. Thanks in advance!

  • 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-09T19:19:21+00:00Added an answer on June 9, 2026 at 7:19 pm

    I don’t think scrollEnabled means what you think it means. It stops the user from scrolling, but it doesn’t stop your code from telling the map to scroll. Same goes for zooms.

    “If you set the value of this property to NO, you may still change the map location programmatically by changing the value in the region property.”

    Ref: http://developer.apple.com/library/ios/DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instp/MKMapView/scrollEnabled

    So forget meddling with scrollEnabled. Look again at your setRegion call. I would think your span is coming out wrong. Log the region and tell us what it sets when it is doing what you want and when it radically zooms out.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
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
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.