grgcombs / MultiRowCalloutAnnotationView

An iOS MapKit callout annotation view with independent cells and accessory actions.
Other
249 stars 53 forks source link

Arrow not always drawn correctly #4

Open janineanne opened 11 years ago

janineanne commented 11 years ago

This is something I discovered in the code from asynchrony.com that you based yours off of. I've been trying to fix it with no success so far, so I went looking to see if there were other good alternatives. It turns out yours does the same thing:

There is no arrow pointing to the pin, but there is a small line jutting out from the lower right corner of the annotation. I believe this is an artifact of the arrow being drawn incorrectly, because if you now dismiss and recall the annotation, the arrow is present and the line is gone.

If you do the same thing and move the pin to the left edge of the screen, the arrow is drawn but it's in the wrong place. Something about the view being moved so that the whole annotation will display is causing this, but so far I have not been able to fix it. Suggestions welcome!

grgcombs commented 11 years ago

I chased this bug on a few occasions and never arrived at a good solution :-(

Sent from my iPhone.

On Oct 10, 2013, at 3:45 PM, Janine Ohmer notifications@github.com wrote:

This is something I discovered in the code from asynchrony.com that you based yours off of. I've been trying to fix it with no success so far, so I went looking to see if there were other good alternatives. It turns out yours does the same thing:

tap the map to close the annotation scroll the map so the pin is right at the right-hand edge of the screen tap the pin to bring up the annotation There is no arrow pointing to the pin, but there is a small line jutting out from the lower right corner of the annotation. I believe this is an artifact of the arrow being drawn incorrectly, because if you now dismiss and recall the annotation, the arrow is present and the line is gone.

If you do the same thing and move the pin to the left edge of the screen, the arrow is drawn but it's in the wrong place. Something about the view being moved so that the whole annotation will display is causing this, but so far I have not been able to fix it. Suggestions welcome!

— Reply to this email directly or view it on GitHub.

janineanne commented 11 years ago

I just sent a pull request which fixes this. I'm trying to decide whether this is a bug I should report to Apple and am curious as to your opinion.

The fundamental problem is that the change to the center coordinate does not take effect immediately. I added a bunch of NSLog statements to illustrate:

2013-10-12 11:04:12.836 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.837 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.837 CalloutDemo[45488:a0b] parent annotation origin: (299.500000, 213.000000) 2013-10-12 11:04:12.837 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.838 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.838 CalloutDemo[45488:a0b] parent annotation origin: (299.500000, 213.000000) 2013-10-12 11:04:12.838 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.839 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.839 CalloutDemo[45488:a0b] parent annotation origin: (299.500000, 213.000000)

2013-10-12 11:04:12.839 CalloutDemo[45488:a0b] Before changing center coordinate: 2013-10-12 11:04:12.840 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.845 CalloutDemo[45488:a0b] parent annotation origin: (299.500000, 213.000000) 2013-10-12 11:04:12.845 CalloutDemo[45488:a0b] new centerCoordinate: 33.141373, -109.170408 2013-10-12 11:04:12.845 CalloutDemo[45488:a0b] After changing center coordinate: 2013-10-12 11:04:12.846 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411

2013-10-12 11:04:12.846 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.846 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.847 CalloutDemo[45488:a0b] parent annotation origin: (299.602020, 213.285828) 2013-10-12 11:04:12.847 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.847 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.848 CalloutDemo[45488:a0b] parent annotation origin: (299.602020, 213.285828) 2013-10-12 11:04:12.851 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.851 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.851 CalloutDemo[45488:a0b] parent annotation origin: (299.602020, 213.285828) 2013-10-12 11:04:13.012 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:13.012 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -120.686943 2013-10-12 11:04:13.013 CalloutDemo[45488:a0b] parent annotation origin: (286.712952, 213.285828) 2013-10-12 11:04:13.142 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:13.143 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -111.037708 2013-10-12 11:04:13.143 CalloutDemo[45488:a0b] parent annotation origin: (230.064514, 213.285828)

You can see that only towards the very end do the center coordinate and the origin of the parent annotation start to change. This happens after drawRect has run, and since the distance to the arrow is in the map view's coordinates, this results in us getting an incorrect value.

Switching from animated:YES to animated:NO on the call to setCenterCoordinate makes the new center coordinate take effect immediately but the map view still doesn't shift until sometime later, as the parent annotation origin shows:

2013-10-12 11:44:02.628 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.629 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -123.648921 2013-10-12 11:44:02.629 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.629 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -123.648921 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -123.648921 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000)

2013-10-12 11:44:02.631 CalloutDemo[46233:a0b] Before changing center coordinate: 2013-10-12 11:44:02.631 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -123.648921 2013-10-12 11:44:02.631 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.631 CalloutDemo[46233:a0b] new centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.632 CalloutDemo[46233:a0b] After changing center coordinate: 2013-10-12 11:44:02.700 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410

2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.702 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.705 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.705 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.705 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.849 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.849 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.849 CalloutDemo[46233:a0b] parent annotation origin: (219.000000, 196.500000) 2013-10-12 11:44:02.993 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.993 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.993 CalloutDemo[46233:a0b] parent annotation origin: (219.000000, 196.500000)

So what do you think, is this a bug I should report, or just an inconvenience we need to work around?

grgcombs commented 11 years ago

Interesting issue.

Haven't looked in iOS 7 to see if we get any new mapView animation blocks that would benefit something like this. I imagine the duration of the recenter animation is a bit more flexible than it is elsewhere in UIKit, so a simple .25 - .3 second block delay may not cut it in every case.

I'd consider at least filing an ER for some better hooks during mapView animations.

G

Sent from my iPhone.

On Oct 12, 2013, at 1:45 PM, Janine Ohmer notifications@github.com wrote:

I just sent a pull request which fixes this. I'm trying to decide whether this is a bug I should report to Apple and am curious as to your opinion.

The fundamental problem is that the change to the center coordinate does not take effect immediately. I added a bunch of NSLog statements to illustrate:

2013-10-12 11:04:12.836 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.837 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.837 CalloutDemo[45488:a0b] parent annotation origin: (299.500000, 213.000000) 2013-10-12 11:04:12.837 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.838 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.838 CalloutDemo[45488:a0b] parent annotation origin: (299.500000, 213.000000) 2013-10-12 11:04:12.838 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.839 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.839 CalloutDemo[45488:a0b] parent annotation origin: (299.500000, 213.000000)

2013-10-12 11:04:12.839 CalloutDemo[45488:a0b] Before changing center coordinate: 2013-10-12 11:04:12.840 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.845 CalloutDemo[45488:a0b] parent annotation origin: (299.500000, 213.000000) 2013-10-12 11:04:12.845 CalloutDemo[45488:a0b] new centerCoordinate: 33.141373, -109.170408 2013-10-12 11:04:12.845 CalloutDemo[45488:a0b] After changing center coordinate: 2013-10-12 11:04:12.846 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411

2013-10-12 11:04:12.846 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.846 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.847 CalloutDemo[45488:a0b] parent annotation origin: (299.602020, 213.285828) 2013-10-12 11:04:12.847 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.847 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.848 CalloutDemo[45488:a0b] parent annotation origin: (299.602020, 213.285828) 2013-10-12 11:04:12.851 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:12.851 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -122.882411 2013-10-12 11:04:12.851 CalloutDemo[45488:a0b] parent annotation origin: (299.602020, 213.285828) 2013-10-12 11:04:13.012 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:13.012 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -120.686943 2013-10-12 11:04:13.013 CalloutDemo[45488:a0b] parent annotation origin: (286.712952, 213.285828) 2013-10-12 11:04:13.142 CalloutDemo[45488:a0b] In relativeParentXPosition: 2013-10-12 11:04:13.143 CalloutDemo[45488:a0b] centerCoordinate: 33.141373, -111.037708 2013-10-12 11:04:13.143 CalloutDemo[45488:a0b] parent annotation origin: (230.064514, 213.285828)

You can see that only towards the very end do the center coordinate and the origin of the parent annotation start to change. This happens after drawRect has run, and since the distance to the arrow is in the map view's coordinates, this results in us getting an incorrect value.

Switching from animated:YES to animated:NO on the call to setCenterCoordinate makes the new center coordinate take effect immediately but the map view still doesn't shift until sometime later, as the parent annotation origin shows:

2013-10-12 11:44:02.628 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.629 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -123.648921 2013-10-12 11:44:02.629 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.629 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -123.648921 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -123.648921 2013-10-12 11:44:02.630 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000)

2013-10-12 11:44:02.631 CalloutDemo[46233:a0b] Before changing center coordinate: 2013-10-12 11:44:02.631 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -123.648921 2013-10-12 11:44:02.631 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.631 CalloutDemo[46233:a0b] new centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.632 CalloutDemo[46233:a0b] After changing center coordinate: 2013-10-12 11:44:02.700 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410

2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.701 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.702 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.705 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.705 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.705 CalloutDemo[46233:a0b] parent annotation origin: (304.000000, 196.500000) 2013-10-12 11:44:02.849 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.849 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.849 CalloutDemo[46233:a0b] parent annotation origin: (219.000000, 196.500000) 2013-10-12 11:44:02.993 CalloutDemo[46233:a0b] In relativeParentXPosition: 2013-10-12 11:44:02.993 CalloutDemo[46233:a0b] centerCoordinate: 30.756890, -109.170410 2013-10-12 11:44:02.993 CalloutDemo[46233:a0b] parent annotation origin: (219.000000, 196.500000)

So what do you think, is this a bug I should report, or just an inconvenience we need to work around?

— Reply to this email directly or view it on GitHub.