【问题标题】:Disable the flickering/blinking of UIMenuItems in UIMenuController in Swift在 Swift 的 UIMenuController 中禁用 UIMenuItems 的闪烁/闪烁
【发布时间】:2019-04-23 00:12:12
【问题描述】:

如何消除UIMenuItemsUIMenuController 中的闪烁/闪烁?我目前有复制和粘贴项目,但是当我的应用在 UILongPressGestureRecognizer 的操作中显示菜单时,它们开始闪烁。

@objc func viewLongPressed(_ recognizer: UILongPressGestureRecognizer) {
    [...]

    UIMenuController.shared.setMenuVisible(true, animated: true)
}

在 iOS 中有这方面的实现吗?

【问题讨论】:

    标签: ios swift uimenucontroller uimenuitem


    【解决方案1】:

    这是因为如果您一直按下识别器视图,UILongPressGestureRecognizer 事件会持续被识别。重复调用UIMenuControllersetMenuVisible(animated:) 方法会导致您描述的闪烁效果。

    要解决此问题,仅当识别器的状态为 .began 时才显示菜单。

    @objc func viewLongPressed(_ recognizer: UILongPressGestureRecognizer) {
        [...]
    
        if recognizer.state == .began {
            UIMenuController.shared.setMenuVisible(true, animated: true)
        }
    }
    

    【讨论】:

    • 谢谢伙计。现在工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 2011-07-31
    • 2013-01-21
    相关资源
    最近更新 更多