Simultaneous pan gesture recognition on iOS
When a PanGestureRecognizer is attached to a view inside a scrolling view, all of the pan gestures are captured by the PanGestureRecognizer and aren't passed to the scrolling view. Therefore, the scrolling view will no longer scroll.
This .NET Multi-platform App UI (.NET MAUI) iOS platform-specific enables a PanGestureRecognizer in a scrolling view to capture and share the pan gesture with the scrolling view. It's consumed in XAML by setting the Application.PanGestureRecognizerShouldRecognizeSimultaneously
attached property to true
:
<Application ...
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
ios:Application.PanGestureRecognizerShouldRecognizeSimultaneously="true">
...
</Application>
Alternatively, it can be consumed from C# using the fluent API:
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
...
Application.Current.On<iOS>().SetPanGestureRecognizerShouldRecognizeSimultaneously(true);
The Application.On<iOS>
method specifies that this platform-specific will only run on iOS. The Application.SetPanGestureRecognizerShouldRecognizeSimultaneously
method, in the Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific
namespace, is used to control whether a pan gesture recognizer in a scrolling view will capture the pan gesture, or capture and share the pan gesture with the scrolling view. In addition, the Application.GetPanGestureRecognizerShouldRecognizeSimultaneously
method can be used to return whether the pan gesture is shared with the scrolling view that contains the PanGestureRecognizer.
Therefore, with this platform-specific enabled, when a ListView contains a PanGestureRecognizer, both the ListView and the PanGestureRecognizer will receive the pan gesture and process it. However, with this platform-specific disabled, when a ListView contains a PanGestureRecognizer, the PanGestureRecognizer will capture the pan gesture and process it, and the ListView won't receive the pan gesture.