UIControl 阻止了我在 iPhone 上的所有视图
UIControl blocking all my views on iPhone
我得到了一个 iPad 设计的应用程序,它使用 SplitViewController
显示两个视图,一个带有联系人列表,另一个带有此联系人的详细信息。 SplitView
在 iPad 上运行良好,但在 iPhone 上有一些问题。
有一个 UIControl 占据主视图的所有大小,它检查用户是否有任何 .touchDown interaction
并调用一些方法来启用或禁用此 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
用于阻止用户在编辑另一个联系人/通过阻止与联系人列表的交互来创建新联系人时在联系人之间切换 和如果在 editing/creating 视图上进行了更改,它会触发一个方法,显示一个弹出窗口说 "modifications have been made do you want to continue without saving ? cancel or continue " :
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
仅在主视图上方,并且在详细视图 (iPad 3D Debugging view), so the pop up shows only when manually cancelling the editing/creating or when trying to change contact while editing/creating, but as the splitView
don't work the same on iPads and iPhones and it appears that on iPhone the Master View is placed above the Detail View, the UIControl
is also above (iPhone 3D Debugging view) 处于编辑模式时启用,它会导致阻止所有屏幕上的交互以及我单击取消弹出窗口的任何地方。
你们能给我解释一下 enable/show 这个 UIControl 只有当 MasterView 显示时而不是在所有地方显示的方法吗?谢谢。
我最终在详细视图上使用了 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
}
}
而且有效! :)
我得到了一个 iPad 设计的应用程序,它使用 SplitViewController
显示两个视图,一个带有联系人列表,另一个带有此联系人的详细信息。 SplitView
在 iPad 上运行良好,但在 iPhone 上有一些问题。
有一个 UIControl 占据主视图的所有大小,它检查用户是否有任何 .touchDown interaction
并调用一些方法来启用或禁用此 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
用于阻止用户在编辑另一个联系人/通过阻止与联系人列表的交互来创建新联系人时在联系人之间切换 和如果在 editing/creating 视图上进行了更改,它会触发一个方法,显示一个弹出窗口说 "modifications have been made do you want to continue without saving ? cancel or continue " :
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
仅在主视图上方,并且在详细视图 (iPad 3D Debugging view), so the pop up shows only when manually cancelling the editing/creating or when trying to change contact while editing/creating, but as the splitView
don't work the same on iPads and iPhones and it appears that on iPhone the Master View is placed above the Detail View, the UIControl
is also above (iPhone 3D Debugging view) 处于编辑模式时启用,它会导致阻止所有屏幕上的交互以及我单击取消弹出窗口的任何地方。
你们能给我解释一下 enable/show 这个 UIControl 只有当 MasterView 显示时而不是在所有地方显示的方法吗?谢谢。
我最终在详细视图上使用了 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
}
}
而且有效! :)