Issue
・I use Xamarin.Forms
・on UWP, it worked
・But on Android and ios, I don't know how implement it.
This is my code
/* Depends on the platform */
switch (Device.RuntimePlatform) {
case Device.iOS:
/* iOS */
// ????
break;
case Device.Android:
/* Android */
// ????
break;
case Device.UWP:
/* UWP */
/* SwipeGestureRecognize */
var leftSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Left };
leftSwipeGesture.Swiped += async (sender, e) => {
// dosomething;
};
var rightSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Right };
rightSwipeGesture.Swiped += async (sender, e) => {
// dosomething;
};
Layout.GestureRecognizers.Add(leftSwipeGesture);
Layout.GestureRecognizers.Add(rightSwipeGesture);
break;
default:
break;
}
/* Add * /
Outputed Error
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for 'java_interop_jnienv_call_float_method_a'.
[Mono] Probing 'java_interop_jnienv_call_float_method_a'.
[Mono] Found as 'java_interop_jnienv_call_float_method_a'.
[ame.calenderap] Explicit concurrent copying GC freed 10027(810KB) AllocSpace objects, 0(0B) LOS objects, 89% free, 2866KB/26MB, paused 25us total 7.627ms
[Mono] GC_TAR_BRIDGE bridges 497 objects 504 opaque 5 colors 497 colors-bridged 497 colors-visible 497 xref 3 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.04ms tarjan 0.09ms scc-setup 0.06ms gather-xref 0.00ms xref-setup 0.00ms cleanup 0.05ms
[Mono] GC_BRIDGE: Complete, was running for 9.34ms
[Mono] GC_MINOR: (Nursery full) time 4.69ms, stw 5.53ms promoted 1600K major size: 2464K in use: 1803K los size: 1024K in use: 162K
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'
Add
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.Platform+DefaultRenderer'.'
Please support me!
Thanks!
Solution
Swipe Gesture Recognizer is cross platforms and you can read the document about how to Add a swipe gesture recognizer.
Here is an example:
In xaml:
<BoxView Color="Teal" ...>
<BoxView.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left" Swiped="OnSwiped"/>
</BoxView.GestureRecognizers>
</BoxView>
In code behind:
public MainPage()
{
InitializeComponent();
var boxView = new BoxView { Color = Color.Teal };
var leftSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Left };
leftSwipeGesture.Swiped += OnSwiped;
boxView.GestureRecognizers.Add(leftSwipeGesture);
}
private void OnSwiped(object sender, SwipedEventArgs e)
{
throw new NotImplementedException();
}
Answered By - nevermore
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.