moonmonkey
moonmonkey

Reputation: 135

How can I determine if NSMagnificationGesture is pinching or zooming

I have an NSMagnificationGesture in the storyboard, it's linked to an action called pinchGesture. Its also linked to an outlet called pinchZoomOut

When I pinch on the trackpad this works well, and triggers the doPinch() function. The problem is it also triggers it if you pinch and if you zoom. I want it to trigger just on pinch gesture, not on zoom.

I figure I need to read the contents out the pinchZoomOut outlet and then have an if statement to determine if its pinching or zooming. The below code is reporting "Cannot convert value of type 'NSMagnificationGestureRecognizer?' to expected argument type 'Double'" if I can get the double from pinchZoomOut I might be able to move forward.

Can anyone please point me in the right direction, my current code is:

@IBOutlet weak var pinchZoomOut: NSMagnificationGestureRecognizer! // the outlet

@IBAction func pinchGesture(_ sender: Any) {

    if pinchZoomOut > 0.3 {
        doPinch() // I want this to trigger on pinch only, not zoom.
    }
}

Any assistance would be gratefully received.

Upvotes: 0

Views: 235

Answers (1)

aheze
aheze

Reputation: 30554

Cannot convert value of type 'NSMagnificationGestureRecognizer?' to expected argument type 'Double'

The error is pretty clear. pinchZoomOut is a NSMagnificationGestureRecognizer?, not a number. You probably want to use its magnification property instead.

if pinchZoomOut.magnification > 0.3 {
    doPinch() // I want this to trigger on pinch only, not zoom.
}

Upvotes: 1

Related Questions