MobileCanvas multi-touch example

Hey all,

I’m looking for an example of managing multiple pointer down and drag events to move and scale an image within a canvas.

I’ve done this a million times on the desktop but it’s a lot different with trying to figure out what various behavior is indicating.

I’m trying to shave some time off the research with a good example.

Anyone?

Xojo really should have added an NSGestureRecognizer by now. There’s one in iOSKit but it’s not currently working with API 2 MobileScreens.

3 Likes

Dosen’t PointerEvent.Pressure give you the information you looking for?

No.
I want to know the difference between someone pinching or spreading, and how much. I want to know if they are dragging something.
I can figure out how to evaluate the events to implement this but I also really want it to feel natural on an iOS device. Figuring out the different pressure intent or the difference between a spread or moving something with 2 fingers isn’t necessarily straight forward.

I wish it were there too.
I’m rubbish with declares on iOS, so inseams out of my reach to implement myself.
I guess I need to do it with “maximum effort” - Deadpool

Interesting this is the first time I’m hearing it’s broken for API2. It complies but doesn’t work?

Hey Jason. Yeah it compiles but the events don’t fire.

is it the use of iosView rather than MobileScreen?

Quite possibly. The changes with API2 were quite extensive but also didn’t allow easy find&replace to fix which is extremely frustrating for a large project. If anyone is able to test replacing iOSView references with MobileScreen to see if that resolves the issues please let me know.

I tried to fix it but ended up with an error I didn’t understand.
I’ll try again and share the issue with this thread.

OK, I search-and-replaced, and overcame the last error I was seeing. Actually it wasn’t bad.

I haven’t used the gesture recognizer. Is there an example of how to use it?

More… just replace iOSView with MobileScreen and then make sure the method extension.view is extending a mobileScreen.

Events are firing… I don’t know what they mean yet, but that’s my next dive.

Thanks.

and I lied. I was catching a separate breakpoint that mislead me.

I don’t know that it’s not working yet. I am not positive of how to implement.
ive dragged a tap recognizer to the window. It doesn’t do anything on its own.
I tried the AddGestureRecognizer method but it crashes the app.

There is a SwipeView in the Extensions module that has pretty much every gesture recognizer on it, in addition to supporting device shake events and letting you draw on it like a canvas. That might be a good place to start seeing how to use them?

In general you create a gesture recognizer and attach it to the view/control with AddGestureRecognizer, then you need to use AddHandler to handle the events for when something happens.

I think you dont want to drag them directly onto the layout, they should be a property of the View/class

I guess I didn’t get everything.

You use iOSMobileUserControl which has an event CreateView.
Inside this event the self.width and self.height are 0. I guess it’s being created before the screen has defined it’s size?

The Xojo documentation says to use MobileUIControl rather than iOSUserControl, which has different events (opening rather than open, and no CreateView).
I tried to merge those two events into opening but when I put the swipeView into a screen the debugger complains that the first control needs to be an iOSView or IOSMobileUserControl…

I had to move the open and create view into a single method and make sure to call it after the screen has fully shown itself.
The tap gesture fires an event, but the pinch does not.

I’ll continue to look into it.

You might have to explicitly enable user interaction on the control to get the pinch recognizer to work

I return true in UsesGestures. How else would I explicitly enable user interaction?

Declare Sub userInteractionEnabled Lib "UIKit" Selector "setUserInteractionEnabled:" _
(obj As ptr, value As Boolean)

userInteractionEnabled(theUIControl.Handle, true)

‘You might have to explicitly enable user interaction’

Every post in this thread makes it feel more and more complicated… :slight_smile:
I had similar issues to Chris in that although Mobilennn classes should be drop in replacements for IOSnn classes, they really aren’t there just yet.

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.