ActionSheet滞后

时间:2017-08-31 13:22:43

标签: ios swift uialertcontroller

我有 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)
}

1 个答案:

答案 0 :(得分:1)

更改animated: true

present(actionSheetController, animated: true, completion: nil)

animated: false省略延迟或动画

present(actionSheetController, animated: false, completion: nil)
相关问题