Smart magnify

I’ve implemented a bunch of gestures into my latest application, but one I’d really like to implement is the Smart Magnify, whereby a user can double click with both fingers to zoom in. Unlike the rotate and standard magnify, this event never fires.

I’ve done some searching and can’t find anything on how to make this work, has anyone implemented this function? If so any pointers?

I haven’t done this but I think smart magnify is 64 bit only.

figures - I’ll give it a try, thanks.

Tried it and it still doesn’t fire :frowning: I’ll come back to it later, thanks for the help.

How did you implement your gestures, Sam?
Or, differently asked: Did you mean gestures or do you want to catch the touch event? If so, I think your view subclass should override acceptsTouchEvents and then the Responder delegate should fire the smartMagnifyWithEvent method.

For Rotate and Magnify, I simply capture the events.

I’ve now added code to override the “acceptsTouchEvents” property and return yes (or True), but the event “smartMagnifyWithEvent:” never gets called. I’ll take another look at it tomorrow.

I can confirm it’s 64 bit only; they ran out of bits for it in the 32 bit event mask :slight_smile:

Here’s a WWDC video session about it, starting at 7m10s. Unfortunately asciiWWDC doesn’t have a transcript.
https://developer.apple.com/videos/play/wwdc2012/231/

Also, acceptsTouchEvents is for receiving the events touchesBeganWithEvent, touchesMovedWithEvent, touchesCancelledWithEvent and touchesEndedWithEvent.

Ha ha…

I tried a 64-Bit app and the event still doesn’t fire. I wonder if it’s been unofficial deprecated, after he talks about the event, he goes onto to say use the ScrollView. (which is not applicable where I’m using gestures). I did also find a really old document on Gestures, but it’s so old it talks about 10.5.2.
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingTouchEvents/HandlingTouchEvents.html

So I threw in the towel and created the most basic Objective-C application, added the event to a custom NSView class, build for 64-Bit and I get the same result, no smartMaginfyWithEvent, however rotateWithEvent does fire.

Oh Geez… Faking it was too easy!

Sub DoubleClick(X As Integer, Y As Integer) if isContextualClick then handleSmartMagnify( me, nil ) End Sub

I like the workaround :slight_smile:

However I tried it in a Swift project and it’s working for me. It’s simply an NSView subclass and smartMagnify changes a value it draws with. Maybe it’s an El Capitan thing, I’m still on Yosemite.

[code]
class ABCanvas: NSView {
//…

override func smartMagnifyWithEvent(event: NSEvent) {
	ABmodel.f[0] = 99;
}

    //...

}[/code]

Huh?! Now that raises more questions, is this broken for Obj-C or is it broken in El Capitan. I’ll test the Xcode project & Xojo project on Yosemite later on.

I’ve posted my Obj-C code on the Apple Dev forums, hopefully someone smarter than me can confirm if I’m missing something, doing it all wrong or it’s broken.

Thanks, I know it’s not the correct way, because basically it incepts two right clicks, yet if you think about it, that’s what double two finger tap does. I guess I should also add code to figure out if the user has disabled smartMagnify in the system (I’ve checked that I have it enabled on my test machines).

Okay, so both the Xojo made application and the Xcode application (Objective-C) do not work for me on 10.10.5 (on a 2015 MacBook).

I’ve posted my Xojo code here http://www.ohanaware.com/xojo/GesturePatcher.zip
Don’t forget to make sure that the project is set to 64-Bit.

My Xcode code is at the following link (if you’re interested) https://forums.developer.apple.com/thread/47621

I’ve tested this on a 2012 Retina MacBook Pro with a Apple Magic Trackpad 1 (and the internal trackpad) and a 2015 MacBook (internal trackpad only).

Looking more and more likely that I’ll use the fake solution for the time being.

Working for me, after also overriding the method in the header

.h

[code]#import <Cocoa/Cocoa.h>

@interface MyCustomNSView : NSView

  • (void)smartMagnifyWithEvent:(NSEvent *)event;

@end[/code]

.m

[code]#import “MyCustomNSView.h”

@implementation MyCustomNSView

  • (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    NSRectFill( NSMakeRect( 0, 0, 100, 100 ) );
    }

  • (void)smartMagnifyWithEvent:(NSEvent *)event {
    NSBeep();
    }

@end[/code]

acceptsTouchEvents isn’t necessary.

No, wait. It works even without the override in the header!? The docs I looked at to remember ObjC overriding show adding the method to the header. So I don’t know. :frowning:

Okay, so here we go… You’re never going to believe this! I’ve found the bug… It’s me!

I’m using it wrong, I’m CLICKING with two fingers… Not gently tapping!

Let the humiliation begin!

@Will Shank Thanks for taking the time out and sharing your Swift code, without you help I don’t think I would have gotten this far. I’m sorry that I was doing it wrong and consumed more time than needed!

I found myself clicking more often than I wanted with the MacBook 3D trackpad. Not sure that is such a good idea for people who do not have a perfect control of their hand.

My intention is use it as a shortcut for zooming in, there is also the menu option so it’s not the only. Especially as the user can disable the gesture in the system prefs.