Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 07-29-2011, 07:13 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 2
Andrey Mishanin is on a distinguished road
Default Custom annotation view is being removed from its superview after setting map view cen

Hi everyone.

I'm working on a location-aware application that is using MKMapView with custom callout bubbles implemented as MKAnnotationView subclass. Yesterday I've encountered a subtle bug when custom annotation view is not being shown. After investigating this issue a bit, I've come up with following results:

- this issue manifests itself only if I'm trying to show custom annotation view immediately after zooming with pinch gesture. So for example if you pinch and then pan the map view everything works fine. Programmatically changing map zoom doesn't cause this issue to appear either
- setting breakpoint in didMoveToSuperview in my custom annotation view class reveals the following backtrace:

Code:
#0  -[CalloutMapAnnotationView didMoveToSuperview] 
#1  0x00186857 in -[UIView(Hierarchy) removeFromSuperview] ()
#2  0x00e14c70 in -[MKAnnotationContainerView _removeAnnotationView:updateCollections:] ()
#3  0x00e196cb in -[MKAnnotationContainerView _removeAnnotationViews:] ()
#4  0x00e19f51 in -[MKAnnotationContainerView _displayAnnotationsInMapRect:includePending:animated:removeOffscreenAnnotations:] ()
#5  0x00e1aaa7 in -[MKAnnotationContainerView _refreshDisplayedAnnotations] ()
#6  0x00dfc508 in -[MKMapView _didChangeRegionMidstream:centerPoint:] ()
#7  0x00e0165c in -[MKMapView _goToCenterCoordinate:zoomLevel:animationType:] ()
#8  0x00df34c3 in -[MKMapView goToCenterCoordinate:zoomLevel:animationType:] ()
#9  0x00e0086f in -[MKMapView setCenterCoordinate:animated:] ()
#10 0x00036fc3 in -[CalloutMapAnnotationView adjustMapRegionIfNeeded] 
#11 0x00037c63 in -[CalloutMapAnnotationView didMoveToSuperview]
#12 0x0017f750 in -[UIView(Internal) _addSubview:positioned:relativeTo:] ()
#13 0x0017dc00 in -[UIView(Hierarchy) insertSubview:atIndex:] ()
#14 0x00e2049f in -[MKAnnotationContainerView _addViewForAnnotation:] ()
#15 0x00e199a5 in -[MKAnnotationContainerView _addViewsForAnnotations:animated:] ()
#16 0x00e19f0d in -[MKAnnotationContainerView _displayAnnotationsInMapRect:includePending:animated:removeOffscreenAnnotations:] ()
#17 0x00e1a9e2 in -[MKAnnotationContainerView showAddedAnnotationsAnimated:] ()
Here, CalloutMapAnnotationView is my custom annotation view class. adjustMapRegionIfNeeded method adjusts map view's center coordinate if annotation is too close to map borders which in turn causes removal of CalloutMapAnnotationView instance from its superview. Why this is happening and what a workaround may be? The corresponding annotation is not being deselected and is still visible ([self.mapView annotationsInMapRect:self.mapView.visibleMapRect] containsObject:self.annotation] returns true).

Further investigation showed even more strange behavior. I added a bunch of debug NSLogs in adjustMapRegionIfNeeded to print each annotation visibility and came up up with following result:

Normal case (custom annotation is displayed):

Custom callout annotation location: (55.821350, 37.497490)
Parent annotation location: (55.821350, 37.497490)
Custom callout annotation visibility before adjustment: 1
Custom callout annotation visibility after adjustment: 1
Parent annotation visibility: 1

Custom annotation is not displayed:

Custom callout annotation location: (55.821350, 37.497490)
Parent annotation location: (55.821350, 37.497490)
Custom callout annotation visibility before adjustment: 1
Custom callout annotation visibility after adjustment: 0
Parent annotation visibility: 1

Despite parent annotation and custom callout annotation having the same location, one of them is visible while the other is not. I'm testing annotation visibility with the following code:

Code:
[[self.mapView annotationsInMapRect:self.mapView.visibleMapRect] containsObject:self.annotation]
More than that, the following assertion fails:

Code:
MKMapRect visibleMapRect = self.mapView.visibleMapRect;
MKMapPoint annotationPoint = MKMapPointForCoordinate(self.annotation.coordinate);
NSAssert(MKMapRectContainsPoint(visibleMapRect, annotationPoint) == [[self.mapView annotationsInMapRect:visibleMapRect] containsObject:self.annotation], @"?!");
Andrey Mishanin is offline   Reply With Quote
Reply

Bookmarks

Tags
custom callout, ios, mapkit, mkannotationview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 384
16 members and 368 guests
Absentia, bignoggins, Diligent, dre, givensur, hussain1982, jbro, jPuzzle, LunarMoon, momolgtm, Newbie123, Paul10, revg, skog, taylor202
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,858
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0