UIMenuController在iOS 13.2中不可见 [英] UIMenuController is not visible in iOS 13.2
本文介绍了UIMenuController在iOS 13.2中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个长按处理程序,显示 UIMenuController
,它在<上照常工作.ios13.2,例如在13.1上可以正常工作,但是在ios13.2上却没有显示,这是我的方法:
I have long press handler that shows UIMenuController
, it works as usual on < ios13.2, for example on 13.1 it works fine, but on ios13.2 it's not shown, here's methods that I had:
private func longPressHandler(sender: UILongPressGestureRecognizer) {
guard
sender.state == .began,
let senderView = sender.view,
let superView = sender.view?.superview
else {
return
}
senderView.becomeFirstResponder()
UIMenuController.shared.setTargetRect(senderView.frame, in: superView)
UIMenuController.shared.setMenuVisible(true, animated: true)
}
private func makeMenuController() {
UIMenuController.shared.menuItems = [
UIMenuItem(title: "ui.report".localized, action: ChatCustomMenuItems.report),
UIMenuItem(title: "ui.chat.reply".localized, action: ChatCustomMenuItems.reply),
UIMenuItem(title: "ui.action.block".localized, action: ChatCustomMenuItems.block)
]
}
在文档中,我发现不建议使用setTargetRect和setMenuVisible
In the documentation I've found out that setTargetRect and setMenuVisible are deprecated
像这样更改,仍然无济于事.有解决办法吗?
Changing like this, still doesn't help. Any solution?
if #available(iOS 13.0, *) {
UIMenuController.shared.isMenuVisible = true
UIMenuController.shared.showMenu(from: superView, rect: senderView.frame)
} else {
UIMenuController.shared.setTargetRect(senderView.frame, in: superView)
UIMenuController.shared.setMenuVisible(true, animated: true)
}
推荐答案
我遇到了完全相同的问题!该问题可能是由于未致电
I've had exactly the same problem! The problem can be caused by not calling
window?.makeKeyAndVisible()
或在 application:didFinishLaunchingWithOptions:
方法
这篇关于UIMenuController在iOS 13.2中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文