我有 ActionSheet 的代码,它的连接速度有点慢?
@IBAction func showAction(_ sender: UIButton) {
let actionSheetController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
actionSheetController.addAction(
UIAlertAction(title: NSLocalizedString("Copy", comment: ""), style: .default, handler: { [weak self] _ in
guard let strongSelf = self else { return }
UIPasteboard.general.string = strongSelf.displayResultLabel.text
let alert = UIAlertController(title: NSLocalizedString("Copied to clipboard", comment: ""), message: "", preferredStyle: .alert)
let when = DispatchTime.now() + 0.5
DispatchQueue.main.asyncAfter(deadline: when){
alert.dismiss(animated: true, completion: nil)
}
self?.present(alert, animated: true, completion:nil)
})
)
actionSheetController.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil))
present(actionSheetController, animated: true, completion: nil)
}
答案 0 :(得分:1)
更改animated: true
present(actionSheetController, animated: true, completion: nil)
到animated: false
省略延迟或动画
present(actionSheetController, animated: false, completion: nil)