在我的iOS swift 3.0
应用程序中,我在当前的ViewController上提供了UIAlertController
工作表实例。但是当我在工作表区域外面(暗淡的半透明背景)点击时,我不想忽略那张纸,因为我已经取消了一个动作。
有什么想法吗?
我有更多按钮的MGSwipeTableViewCell。当用户点击那个"更多"按钮,代码执行。
func onClickMore(for vmCell: VmCell) {
let sheet = UIAlertController(title: vmCell.vmItem?.vmNameWithoutIp, message: vmCell.vmItem?.ipAddress, preferredStyle: .actionSheet)
sheet.addAction(UIAlertAction(title: "Create Ticket", style: .default) { (action: UIAlertAction) in
})
sheet.addAction(UIAlertAction(title: "Start VM", style: .default) { (action: UIAlertAction) in
})
sheet.addAction(UIAlertAction(title: "Restart VM", style: .default) { (action: UIAlertAction) in
})
sheet.addAction(UIAlertAction(title: "Stop VM", style: .destructive) { (action: UIAlertAction) in
})
sheet.addAction(UIAlertAction(title: "Cancel", style: .cancel) { (action: UIAlertAction) in
})
present(sheet, animated: true) {
sheet.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil))
}
}
答案 0 :(得分:4)
键入警告
您可以下载sample project
将手势识别器添加到alertController superview 以处理用户交互
self.present(alertController, animated: true, completion: {() -> Void in
alertController.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil)
})
关于那个动作什么都不做
<强>更新强>
let alertController = UIAlertController(title: "Do something", message: "With this", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Done", style: .default) { action in
// perhaps use action.title here
})
self.present(alertController, animated: true, completion: {() -> Void in
alertController.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil))
})
表示UIAlertController输入为actionSheet
您可以下载sample project
你可以用两种方式做到这一点
选项1
alert.view.superview.subviews[0] isUserInteractionEnabled = false
选项2
alert.view.superview?.subviews[0].addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil))
例如
self.present(sheet, animated: true, completion: {() -> Void in
// sheet.view.superview?.subviews[0].isUserInteractionEnabled = false;
sheet.view.superview?.subviews[0].addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil))
})
完整代码
let sheet = UIAlertController(title: "karthik", message: "check with", preferredStyle: .actionSheet)
sheet.addAction(UIAlertAction(title: "Create Ticket", style: .default) { (action: UIAlertAction) in
})
sheet.addAction(UIAlertAction(title: "Start VM", style: .default) { (action: UIAlertAction) in
})
sheet.addAction(UIAlertAction(title: "Restart VM", style: .default) { (action: UIAlertAction) in
})
sheet.addAction(UIAlertAction(title: "Stop VM", style: .destructive) { (action: UIAlertAction) in
})
sheet.addAction(UIAlertAction(title: "Cancel", style: .cancel) { (action: UIAlertAction) in
})
self.present(sheet, animated: true, completion: {() -> Void in
// sheet.view.superview?.subviews[0].isUserInteractionEnabled = false;
sheet.view.superview?.subviews[0].addGestureRecognizer(UITapGestureRecognizer(target: self, action: nil))
})