PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

TouchPinch

The TouchPinch event fires when the player uses two fingers to make a pinch or pull gesture on the UI element using a touch-enabled device. A pinch happens when two or more fingers move closer together, and a pull happens when they move apart. This event fires in conjunction with GuiObject/TouchPan. This event is useful for allowing the player to manipulate the scale (size) of UI elements on the screen, and is most often used for zooming features.

This event fires with a table of DataType/Vector2 that describe the relative screen positions of the fingers involved in the gesture. In addition, it fires several times with multiple Enum/UserInputStates: Begin after a brief delay, Change when the player moves a finger during the gesture and finally once more with End. It should be noted that the scale should be used multiplicatively.

Since this event requires at least two fingers, it is not possible to be simulated in Studio using the emulator and a mouse; you must have a real touch-enabled device (and also least two fingers, try asking a friend). Below is an animation of TouchPinch firing on the black semitransparent Frame that covers the screen (note the touch positions marked with white circles). The event is being used to manipulate the scale of the TextLabel that says “Hi!”. The code for this can be found in the code samples.

TouchPinch firing on a real touch device

This event is part of a family of touch-related events. Other events like this one are GuiObject/TouchTap, GuiObject/TouchRotate, GuiObject/TouchPan, GuiObject/TouchLongPress and Guiobject/TouchSwipe. In addition, UserInputService has a similarly named event that is not restricted to a specific UI element: UserInputService/TouchPinch.

Parameters

Name Type Default Description

Code Samples


Pinch/Pull Scaling

This code sample is meant for a LocalScript within an inner Frame that is inside an outer Frame, or other GuiObject. It allows the player to scale the inner frame by performing a GuiObject/TouchPinch gesture on the outer frame.