gpt4 book ai didi

ios - UIControl 阻止了我在 iPhone 上的所有 View

转载 作者:行者123 更新时间:2023-11-28 08:42:28 25 4
gpt4 key购买 nike

我得到了一个使用 SplitViewController 的 iPad 设计的应用程序,该应用程序显示两个 View ,一个带有联系人列表,另一个带有此联系人的详细信息。 SplitView 在 iPad 上运行良好,但在 iPhone 上存在一些问题。

有一个 UIControl 占用主视图的所有大小,检查用户是否有任何 .touchDown 交互 以及调用一些方法来启用或禁用此 UIControl 取决于我们是在编辑联系人模式还是不允许用户与屏幕交互:

private var disableInteractionClosure: (()->())?
private lazy var interactionOverlay: UIControl = {
let c = UIControl()
c.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]
c.addTarget(self, action: "interactionOverlayAction", forControlEvents: .TouchDown)
return c
}()

func disableInteractionWhileEditingWithClosure(callback: ()->()) {
if disableInteractionClosure == nil {
disableInteractionClosure = callback
/* display control overlay */
interactionOverlay.frame = navigationController!.view.bounds
navigationController!.view.addSubview(interactionOverlay)
}
}

func interactionOverlayAction() {
disableInteractionClosure!()
}

func enableInteraction() {
disableInteractionClosure = nil
interactionOverlay.removeFromSuperview()
}

基本上,UIControl 用于阻止用户在编辑另一个联系人时在联系人之间切换/通过阻止与联系人列表的交互来创建新联系人,如果更改已经在编辑/创建 View 上进行了它触发一个方法,显示一个弹出窗口说“修改已经完成,你想继续而不保存吗?取消或继续”:

func cancel() {
self.view.endEditing(true)

let closure: ()->() = {
self.layoutView.willResign()
self.delegate?.tabDetailsControllerDidCancel(self)
}

if layoutView.hasChanges() {
MKAlertViewController().instantaneousAlert(title: "Modification apportées", message: "Êtes-vous sur de vouloir continuer sans sauvegarder les modifications ?", confirmButtonTitle: "Oui", cancelButtonTitle: "Annuler", confirmed: { () -> Void in
closure()
}, canceled: { () -> Void in

})
} else {
closure()
}

}

它在 iPad 上工作正常,因为 UIControl 仅在主视图上方,并且在详细 View (iPad 3D Debugging view) 的编辑模式下启用,因此弹出窗口仅在手动取消时显示编辑/创建或在编辑/创建时尝试更改联系人时,但由于 splitView 在 iPad 和 iPhone 上的工作方式不同,而且在 iPhone 上似乎主视图位于详细信息上方查看,UIControl 也在上方 ( iPhone 3D Debugging view ),它会导致阻止所有屏幕上的交互,无论我点击什么地方都会显示取消弹出窗口。

你们能否向我解释一种仅在 MasterView 显示时而不是在所有地方显示时启用/显示此 UIControl 的方法。谢谢。

最佳答案

我最终在详细 View 上使用了 viewWillDisappear :

override func viewWillDisappear(animated: Bool) {

super.viewWillDisappear(animated)

if self.isMovingFromParentViewController() || self.isBeingDismissed() {
if editingMode {
shared.contactsListController.disableInteractionWhileEditingWithClosure({ (_) in
self.tabDetailsController.cancel()
})
shared.contactsListController.disableToolbar()
} else {
shared.contactsListController.enableInteraction()
shared.contactsListController.enableToolbar()
}
self.navigationController?.toolbar.alpha = 1
}
}

并修改主视图上的 disableInteractionWhileEditingWithClosure 方法:

func disableInteractionWhileEditingWithClosure(callback: ()->()) {
if disableInteractionClosure == nil {
disableInteractionClosure = callback
/* display control overlay */
interactionOverlay.frame = navigationController!.view.bounds

view.addSubview(interactionOverlay) // this line
}
}

而且有效! :)

关于ios - UIControl 阻止了我在 iPhone 上的所有 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36127040/

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