xamarin - 使用 xamarin 表单从页面中删除向后滑动手势
问题描述
有没有办法可以在我的项目的一个页面上禁用 iOS 的向后滑动到上一页选项?
解决方案
您可以通过实现自定义渲染器并为此设置正确的属性来实现此目的。您可以在下面看到一个示例实现。在这种情况下,正确的属性是InteractivePopGestureRecognizer
您需要设置为 false 的。
这样做ViewWillAppear
是为了NavigationController
初始化。
using DisableSwipe.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(ContentPage), typeof(NoBackSwipeRenderer))]
namespace DisableSwipe.iOS
{
public class NoBackSwipeRenderer : PageRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (ViewController?.NavigationController != null)
ViewController.NavigationController.InteractivePopGestureRecognizer.Enabled = false;
}
}
}
推荐阅读
- ajax - 图片上传后页面未使用 Jsp 重定向到 ajax 调用成功
- reactjs - JWT - req.cookies 未定义
- python - 如何使用 ctypes 调用具有双下划线函数名的 DLL 函数?
- ramda.js - Ramda.js - 如何使 R.merge 点免费 - 具有相同数据集的 2 个函数
- html - HTML 图片库在左下方浮动
- php - 合并 PHP 数组以创建命名键和唯一值
- python - SQLAlchemy / Graphene - 如何对查询集进行分组或操作
- javascript - javascript树向特定级别的对象添加新属性
- sql - Oracle SQL 分区范围全部而不是范围单一
- visual-studio - 如何从 Visual Studio 2019 源代码管理身份验证窗口中删除帐户?