Search code examples
swiftuitextview3dtouchuimenucontroller

Close edit menu when 3D touch in textfield swift


enter image description here

How to close this menu when 3D touch click in textfiled using swift


Solution

  • Create one none case which return false and call that case when 3D touch start and call select case when 3D touch ended.

    override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool
            {
                switch self.currentState {
                case .select:
                    if action == #selector(select(_:)) || action == #selector(selectAll(_:))
                    {
                        return true
                    }
                case .copy:
                    if action == #selector(copy(_:))
                    {
                        return true
                    }
                case .paste:
                    if action == #selector(paste(_:)) || action == #selector(select(_:)) || action == #selector(selectAll(_:))
                    {
                        return true
                    }
                case .none:
                    return false
                }
                return false
            }