would someone please review my code commit (doubletap -> [delegate afterMapMove])

25 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Colin Prepscius

belum dibaca,
13 Feb 2009, 15.04.4413/02/09
kepadaroute-...@googlegroups.com

There were two AYE's and zero NAYE's. 


I've just committed code related to the "doubletap -> [delegate afterMapMove]" problem.  I probably should have branched and not committed to the trunk yet, but oh well.  It wasn't so trivial after all, so I'd really appreciate if someone could review the code.  I'm sure it's not the most elegant code, and in the process I've probably rendered some old code into cruft.  I do hope I didn't break anything.


Anyway, the problem was that this:


               if (delegateHasDoubleTapOnMap) {

                       [delegate doubleTapOnMap: self At: lastGesture.center];

               } else {

                       // Default behaviour matches built in maps.app

                       ### CALL DELEGATE BEFOREMAPZOOM ###

                       [[self contents] zoomInToNextNativeZoomAt: [touch locationInView:self] animated:YES];

                       ### CALL DELEGATE AFTERMAPZOOM ###

               }


wasn't gonna work, because of the animation - what we really want is the delegate's method to be called after the animation is complete.  I didn't want to pass the delegate through to the RMMapContents, because I was assuming that would violate too much encapsulation.  So, I created another protocol in RMMapContents.h: 


@protocol RMMapContentsAnimationCallback <NSObject>

@optional

- (void)animationFinishedWithZoomFactor:(float)zoomFactor near:(CGPoint)p;

@end


...and made RMMapView implement it.  RMMapView now calls 


if (delegateHasDoubleTapOnMap) {

[delegate doubleTapOnMap: self At: lastGesture.center];

} else {

// Default behaviour matches built in maps.app

float nextZoomFactor = [[self contents] getNextNativeZoomFactor];

if (nextZoomFactor != 0)

[self zoomByFactor:nextZoomFactor near:[touch locationInView:self] animated:YES];

}


...so, I added the getNextNativeZoomFactor to RMMapContents, and zoomByFactor:...animated: to RMMapView.  The latter calls [contents zoomByFactor:...withCallback:self], which in turn puts the callback into the timer's userInfo dictionary.  When the timer finishes, it calls the callback, which then calls the delegate.  


Er, not so nice, I'm guessing.


Is there anyone besides Joseph who's familiar with all the code now?  Has Mr. Gentle successfully turned over the project to anyone?


thanks,

Colin


lepah

belum dibaca,
24 Feb 2009, 15.52.5324/02/09
kepadaroute-me
Hi Colin,

It works but its a bit messy and a little weird in my opinion. An
alternative, perhaps cleaner solution would be to create a
RMMapContents delegate with the animationFinishedWithZoomFactor
method. When the RMMapView creates the RMMapContents object it sets
itself as the RMMapContent's delegate. Then in the RMMapView you can
do whatever you want such as pass it through to the existing RMMapView
delegate method afterMapZoom or you could create another RMMapView
delegate method afterMapAnimatedZoom so people can choose how they
want to use it.

I'm happy to make these minor changes if you would like.

Another note with regards to this animated zoom, when it gets called
(via the double tap), it doesn't seem smooth, it jerks, (it appears
its the NSTimer as its not guaranteed to be called at the exact time
you specific) Have you, or anyone found a 'smoother' solution to
this?

thanks,
Matt

Hal Mueller

belum dibaca,
24 Feb 2009, 20.32.3524/02/09
kepadaroute-...@googlegroups.com
Colin/Matt: in this patch, having a delegate prevents the normal behavior from happening. This seems very unCocoaish to me.

Why not just get rid of the "else", and then fire the delegate (either before or after) if it exists?

Hal
--
Hal Mueller
halmu...@gmail.com
Seattle, Washington

Colin Prepscius

belum dibaca,
24 Feb 2009, 22.53.0924/02/09
kepadaroute-...@googlegroups.com
lepah: reviewing your code comments, not finished yet.  Yeah, the zoom animation ain't so nice.  I'll play around with the numbers, maybe it can be tweaked.  Thanks for having a look!

Hal: I dunno, I didn't do that part.  What if you wanted to make double tap NOT zoom in, instead do something else?  You'd need it to look pretty much the way it does, or else set a flag in the object (themapview.doubleTapZooms=NO), or have another delegate method (-(BOOL)doubleTapZooms).  If you don't override the delegate method, I assume the meaning is: "the map will do its own thing (zoom)", in which case you'd still want before/afterZoom, and you probably wouldn't want zoom.  Actually, never mind:  who am I to say "you'll never want onDoubleTap if the map is doing its default behavior (zooming) on double tap"?  Maybe you would. 

So, I'd suggest:  double tap always fires the delegate's onDoubleTap, and whether the map zooms on double tap is controlled by a boolean instance variable in RMMapView or RMMapContents ("doubleTapZooms", or something, defaulting to true, er, YES).  OUI?

Colin

mike hill

belum dibaca,
25 Feb 2009, 10.50.2925/02/09
kepadaroute-me
I am almost finished with my patch which adds a delegate:

- (void) afterMapDecelerated: (RMMapView*) map

this fires when the map has finished moving with deceleration (this
part is working)
or when the user drags and lets go (still working on this part). I
wanted a delegate I could count
on to reload my markers without any timer sillyness.

is this kind of what you are trying to do? not sure if I understand
what your code is attempting ..

-mike

On Feb 24, 10:53 pm, Colin Prepscius <colinprepsc...@gmail.com> wrote:
> lepah: reviewing your code comments, not finished yet.  Yeah, the zoom
> animation ain't so nice.  I'll play around with the numbers, maybe it can be
> tweaked.  Thanks for having a look!
>
> Hal: I dunno, I didn't do that part.  What if you wanted to make double tap
> NOT zoom in, instead do something else?  You'd need it to look pretty much
> the way it does, or else set a flag in the object
> (themapview.doubleTapZooms=NO), or have another delegate method
> (-(BOOL)doubleTapZooms).  If you don't override the delegate method, I
> assume the meaning is: "the map will do its own thing (zoom)", in which case
> you'd still want before/afterZoom, and you probably wouldn't want zoom.
> Actually, never mind:  who am I to say "you'll never want onDoubleTap if the
> map is doing its default behavior (zooming) on double tap"?  Maybe you
> would.
>
> So, I'd suggest:  double tap always fires the delegate's onDoubleTap, and
> whether the map zooms on double tap is controlled by a boolean instance
> variable in RMMapView or RMMapContents ("doubleTapZooms", or something,
> defaulting to true, er, YES).  OUI?
>
> Colin
>
> On Tue, Feb 24, 2009 at 8:32 PM, Hal Mueller <halmuel...@gmail.com> wrote:
> > Colin/Matt: in this patch, having a delegate prevents the normal behavior
> > from happening. This seems very unCocoaish to me.
> > Why not just get rid of the "else", and then fire the delegate (either
> > before or after) if it exists?
>
> > Hal
>
> > halmuel...@gmail.com
> > Seattle, Washington

Colin Prepscius

belum dibaca,
25 Feb 2009, 11.08.2125/02/09
kepadaroute-...@googlegroups.com
Yeah, that's what my patch is supposed to do.  Although, really, it was more of a bugfix:  prior to my patch, if you double-tapped on the map, it would zoom in, but would not call the delegate methods before/afterMapZoom.  And yeah, this patch ought to work without any timer silliness as well - the last NSTimer invokation (from double tap), besides turning itself off, will (ultimately) call the delegates.

What causes the map to move with deceleration?  Pinch zoom and drag?

If I were overly literal, I might expect your delegate method to be called after the map is finished decelerating (but not finished moving), after it reaches a constant velocity.

btw - are you mike hill of c-ville?

Tracy

belum dibaca,
25 Feb 2009, 11.39.2825/02/09
kepadaroute-me
There are also similar quirks with some of the other delegates...
Here's my patch to allow taps to come through undermarkers...
Previous markers or
labels would swallow single taps...

This works for me, but I bet someone else would want the previous. We
probably need to expand the functionality here so that the user is
told the singleTap was part of a marker (and which marker it was)
so that they can make their own determination.

--- RMMapView.m (revision 193)
+++ RMMapView.m (working copy)
@@ -399,14 +402,10 @@
CALayer *superlayer = [hit superlayer];

// See if tap was on a marker or marker label and send delegate
protocol method
- if ([hit isMemberOfClass: [RMMarker class]]) {
- if (delegateHasTapOnMarker) {
- [delegate tapOnMarker:(RMMarker*)hit onMap:self];
- }
- } else if (superlayer != nil && [superlayer isMemberOfClass:
[RMMarker class]]) {
- if (delegateHasTapOnLabelForMarker) {
- [delegate tapOnLabelForMarker:(RMMarker*)superlayer onMap:self];
- }
+ if (delegateHasTapOnMarker && [hit isMemberOfClass: [RMMarker
class]]) {
+ [delegate tapOnMarker:(RMMarker*)hit onMap:self];
+ } else if (delegateHasTapOnLabelForMarker && (superlayer != nil &&
[superlayer isMemberOfClass: [RMMarker class]])) {
+ [delegate tapOnLabelForMarker:(RMMarker*)superlayer onMap:self];
}
else if (delegateHasSingleTapOnMap) {
[delegate singleTapOnMap: self At: [touch locationInView:self]];


On Feb 25, 8:08 am, Colin Prepscius <colinprepsc...@gmail.com> wrote:
> Yeah, that's what my patch is supposed to do.  Although, really, it was more
> of a bugfix:  prior to my patch, if you double-tapped on the map, it would
> zoom in, but would not call the delegate methods before/afterMapZoom.  And
> yeah, this patch ought to work without any timer silliness as well - the
> last NSTimer invokation (from double tap), besides turning itself off, will
> (ultimately) call the delegates.
>
> What causes the map to move with deceleration?  Pinch zoom and drag?
>
> If I were overly literal, I might expect your delegate method to be called
> after the map is finished decelerating (but not finished moving), after it
> reaches a constant velocity.
>
> btw - are you mike hill of c-ville?
>

Quazie

belum dibaca,
14 Mar 2009, 23.49.0414/03/09
kepadaroute-me
Bumping this to make sure we don't lose this patch.

On Feb 25, 12:39 pm, Tracy <tracy.har...@gmail.com> wrote:
> There are also similar quirks with some of the other delegates...
> Here's mypatchto allow taps to come through undermarkers...
> > Yeah, that's what mypatchis supposed to do.  Although, really, it was more
> > of a bugfix:  prior to mypatch, if you double-tapped on the map, it would
> > zoom in, but would not call the delegate methods before/afterMapZoom.  And
> > yeah, thispatchought to work without any timer silliness as well - the
> > last NSTimer invokation (from double tap), besides turning itself off, will
> > (ultimately) call the delegates.
>
> > What causes the map to move with deceleration?  Pinch zoom and drag?
>
> > If I were overly literal, I might expect your delegate method to be called
> > after the map is finished decelerating (but not finished moving), after it
> > reaches a constant velocity.
>
> > btw - are you mike hill of c-ville?
>
> > On Wed, Feb 25, 2009 at 10:50 AM, mike hill <michaelh...@gmail.com> wrote:
>
> > > I am almost finished with mypatchwhich adds a delegate:
> > > > > Colin/Matt: in thispatch, having a delegate prevents the normal
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru