要求:
长按webview文字只弹出分享,长按textfiled,弹出比如粘贴或者全选
之前方案是clear系统所有的菜单,添加自定义的分享按钮,如果完成以上需求,目前来看,不能remove所有系统菜单,需要remove指定的菜单,
Android系统默认的菜单如下:
中文:分享,复制,全选,网页搜索,浏览器搜索,翻译,快速搜索,
英文:Copy,Share,Select all,Web Search
繁体:複製,全部選取,網頁搜尋,全選
IOS端,需要显示和隐藏端在如下方法进行处理:
override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
UIMenuController.shared.isMenuVisible = false
if #available(iOS 10, *) {
if action == #selector(UIResponderStandardEditActions.select(_:))
|| action == #selector(UIResponderStandardEditActions.cut(_:))
|| action == #selector(UIResponderStandardEditActions.paste(_:))
|| action == #selector(UIResponderStandardEditActions.delete(_:))
|| (action == #selector(customShare))
{
return super.canPerformAction(action, withSender:sender)
}
} else {
if action == #selector(select(_:))
|| action == #selector(cut(_:))
|| action == #selector(paste(_:))
|| action == #selector(delete(_:))
|| (action == #selector(customShare))
{
return super.canPerformAction(action, withSender:sender)
}
}
return false
}
其它selector如下:
public protocol UIResponderStandardEditActions : NSObjectProtocol {
@available(iOS 3.0, *)
optional func cut(_ sender: Any?)
@available(iOS 3.0, *)
optional func copy(_ sender: Any?)
@available(iOS 3.0, *)
optional func paste(_ sender: Any?)
@available(iOS 3.0, *)
optional func select(_ sender: Any?)
@available(iOS 3.0, *)
optional func selectAll(_ sender: Any?)
@available(iOS 3.2, *)
optional func delete(_ sender: Any?)
@available(iOS 5.0, *)
optional func makeTextWritingDirectionLeftToRight(_ sender: Any?)
@available(iOS 5.0, *)
optional func makeTextWritingDirectionRightToLeft(_ sender: Any?)
@available(iOS 6.0, *)
optional func toggleBoldface(_ sender: Any?)
@available(iOS 6.0, *)
optional func toggleItalics(_ sender: Any?)
@available(iOS 6.0, *)
optional func toggleUnderline(_ sender: Any?)
@available(iOS 7.0, *)
optional func increaseSize(_ sender: Any?)
@available(iOS 7.0, *)
optional func decreaseSize(_ sender: Any?)
@available(iOS 13.0, *)
optional func updateTextAttributes(conversionHandler: ([NSAttributedString.Key : Any]) -> [NSAttributedString.Key : Any])
}