如何使用Swift 3显示UIMenuController

时间:2016-10-11 04:38:44

标签: ios swift3 uimenucontroller

我试图让菜单控制器显示。
我想我打算调用canBecomeAFirstResponder()并覆盖它但它不再是一个函数,它现在是一个计算变量。

我做了以下事情:

class DrawView: UIView {

     func tap(gestureRecognizer: UIGestureRecognizer) {

        let menu = UIMenuController.shared
        becomeFirstResponder() // This gives the warning "Result of call to becomeFirstResponder() not used"
        let deleteItem = UIMenuItem(title: "Delete", action: #selector(DrawView.deleteLine))
        menu.menuItems = [deleteItem]

        menu.setTargetRect(CGRect(x: point.x, y: point.y, width: 20, height: 20), in: self)
        menu.setMenuVisible(true, animated: true)

        setNeedsDisplay()
    }


    func deleteLine(sender: AnyObject) {

    }

    override var canBecomeFirstResponder: Bool {
        return true
    }
}

问题是当我点按它时会识别水龙头,但菜单不会显示。

0 个答案:

没有答案