![](/img/trans.png)
[英]Xamarin.Forms - Get cellphone provider for both Android and ios
[英]Xamarin.Forms : How to get and add swipe events on Android and ios?
・使用Xamarin.Forms
・在 UWP 上,它工作
・但是在 Android 和 ios 上,我不知道如何实现。
这是我的代码
/* 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;
}
/* 添加 * /
输出错误
[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.'
添加
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'Xamarin.Forms.Platform.Android.Platform+DefaultRenderer'.'
请支持我!
谢谢!
滑动手势识别器是跨平台的,您可以阅读有关如何添加滑动手势识别器的文档。
这是一个例子:
在 xaml 中:
<BoxView Color="Teal" ...>
<BoxView.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left" Swiped="OnSwiped"/>
</BoxView.GestureRecognizers>
</BoxView>
在后面的代码中:
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.