let MenuController: UIMenuController = UIMenuController.sharedMenuController() MenuController.menuVisible = true MenuController.arrowDirection = UIMenuControllerArrowDirection.Down MenuController.setTargetRect(CGRectMake(100,80,50,50),inVIEw: self.vIEw) let MenuItem_1: UIMenuItem = UIMenuItem(Title: "Menu",action: "delete:") let MenuItems: NSArray = [delete] MenuController.menuItems = MenuItems@H_419_12@解决方法 为了实际显示菜单,您需要执行以下 *** 作:>在获得sharedMenuController之前调用becomeFirstResponder()
>最后调用menu.setMenuVisible(true,animated:true)
>覆盖canBecomeFirstResponder函数
>覆盖canPerformAction函数
>为选择器编写功能这是一个例子
func someFunc() { becomeFirstResponder() var menu = UIMenuController.sharedMenuController() var deleteItem = UIMenuItem(Title: "Delete me",action: Selector("deleteline")) menu.menuItems = [deleteItem] menu.setTargetRect(CGRectMake(100,inVIEw: self) menu.setMenuVisible(true,animated: true)}func deleteline() { //Do something here}overrIDe func canBecomeFirstResponder() -> Bool { return true}overrIDe func canPerformAction(action: Selector,withSender sender: AnyObject?) -> Bool { // You need to only return true for the actions you want,otherwise you get the whole range of // iOS actions. You can see this by just removing the if statement here. if action == Selector("deleteline") { return true } return false}@H_419_12@ 总结以上是内存溢出为你收集整理的xcode – Swift-设置可见菜单控制器全部内容,希望文章能够帮你解决xcode – Swift-设置可见菜单控制器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
概述我正在尝试显示UimenuController,但我无法查看它.我能怎么做? let MenuController: UIMenuController = UIMenuController.sharedMenuController() MenuController.menuVisible = true MenuController.arrowDirection = UIMenuControll 我正在尝试显示UimenuController,但我无法查看它.我能怎么做?
赞
(0)
打赏
微信扫一扫
支付宝扫一扫
xCode 4添加文件夹
上一篇
2022-05-24
iphone – 如何只运行一次代码?
下一篇
2022-05-24
评论列表(0条)