gpt4 book ai didi

ios - 当发生一些特定操作时,如何禁用 View Controller 中的旋转?

转载 作者:行者123 更新时间:2023-11-29 05:10:46 25 4
gpt4 key购买 nike

在执行某些特定操作时, View Controller 是否有特定值或方法来禁用旋转?例如,我想允许在该 View Controller 上一直旋转,除了一件事。

func deleteAction(at indexPath: IndexPath) -> UIContextualAction {
let action = UIContextualAction(style: .destructive, title: "Remove") { (action, view, completion) in
DispatchQueue.main.async {
self.showActivityIndicator()
}
DispatchQueue.global(qos: .default).async {
SingleTon.shared.deleteWordFromVocabulary(word: SingleTon.shared.getWords()[indexPath.section][indexPath.row], indexPath: indexPath.row)

DispatchQueue.main.async {
self.tableView.deleteRows(at: [indexPath], with: .automatic)
self.stopActivityIndicator()
}
}
}

当事件指示器出现时,我想禁用 View Controller 旋转。当我的事件指示器消失时,我想启用 View Controller 旋转回来。

最佳答案

是的,您可以使用一种方法来限制支持的界面方向:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { self.restrictRotation /* could be limited or not */ }

它应该位于AppDelegate内部,但您可以使用通知/观察者之类的东西或某种委托(delegate)模式将限制传递给AppDelegate或从其他地方设置它。

关于ios - 当发生一些特定操作时,如何禁用 View Controller 中的旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59707311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com