亲爱的 StackOverflow 用户,您好,
我在 Xamarin.iOS 应用程序中遇到了一个烦人的问题。简而言之,从 iOS 17 开始,我的很多 UITextField 现在都提供了自动填充功能。当我点击“自动填充”按钮时,iOS 会要求我填写联系方式或密码。
请不要将此与 iOS 键盘上提供的自动填充功能混淆。键盘端一切正常。
这是显示相关自动填充功能的屏幕截图:
我尝试通过
CanPerform()
选择器禁用弹出窗口,但是 iOS 似乎没有将自动填充功能传递给 CanPerform()
。
这是我的代码
CanPerform()
:
public bool EvaluateEditSelector(string selector) //gets called by CanPerformAction()
{
if (AllowCopyPaste || CopyPasteOverride)
{
switch (selector)
{
case "cut:":
return showCopyPaste;
case "copy:":
return showCopyPaste;
case "select:":
return showCopyPaste;
case "selectAll:":
return showCopyPaste;
case "paste:":
return showCopyPaste;
case "makeTextWritingDirectionLeftToRight:": //Last selector
showCopyPaste = true;
return false;
default:
return false;
}
}
else
{
return false;
}
}
我检查了 UIMenuBuilder 或者 UIMenuIdentifiers 是否有自动填充的标识符,但是我还没有找到相应的标识符。
这是
BuildMenu()
中的代码:
public override void BuildMenu(IUIMenuBuilder builder)
{
if (Device.GetSystemVersion().Major >= 16) //helper method to check system version
{
builder.RemoveMenu(UIMenuIdentifierExtensions.GetConstant(UIMenuIdentifier.Lookup));
}
base.BuildMenu(builder);
}
提前感谢您的关注。
请尝试一下。
@available(iOS 13.0, *)
override func buildMenu(with builder: UIMenuBuilder) {
if #available(iOS 17.0, *) {
builder.remove(menu: .autoFill)
}
super.buildMenu(with: builder)
}