簡體   English   中英

禁用UIAlertController框架外的觸摸以取消

[英]Disable touch outside UIAlertController frame to cancel

我有一個UIAlertController與風格ActionSheet

我已經添加了cancel動作。

事實是,由於某些原因,當用戶在ActionSheet框外點擊時,警報將被關閉。

如何禁用此行為? 我希望用戶直接按“取消”按鈕。

迅捷4 / Xcode 11

你好。 要禁用用戶交互(例如:點擊取消按鈕之外的任何位置),請在警報功能中調用present方法,並按以下代碼設置其完成關閉。

present(alertController, animated: true) {
   alertController.view.superview?.subviews[0].isUserInteractionEnabled = false
}

整個例子:

func alertMe() {

let alertController = UIAlertController(title: "Tapping Test", message: "User Interaction on the view is disabled", preferredStyle: .actionSheet)

let cancelAction = UIAlertAction(title: "cancel", style: UIAlertActionStyle.cancel) { UIAlertAction in

// do something/call someone/or nothing :)
NSLog("cancel Button is Pressed")

}

alertController.addAction(cancelAction)

present(alertController, animated: true){
            alertController.view.superview?.subviews[0].isUserInteractionEnabled = false
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM