UIMenuController is not visible in iOS 13.2

↘锁芯ラ 提交于 2020-01-24 12:19:08

问题


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)
    ]
}

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)
}

回答1:


I've had exactly the same problem! The problem can be caused by not calling

window?.makeKeyAndVisible()

or calling it before application:didFinishLaunchingWithOptions: method



来源:https://stackoverflow.com/questions/59176844/uimenucontroller-is-not-visible-in-ios-13-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!