【问题标题】:UIControl blocking all my views on iPhoneUIControl 阻止了我在 iPhone 上的所有视图
【发布时间】:2016-03-21 09:20:29
【问题描述】:

我有一个 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 用于阻止用户在用户编辑另一个联系人/通过阻止与联系人列表交互来创建新联系人时在联系人之间切换以及是否已对编辑/创建视图它会触发一个方法,该方法显示一个弹出窗口,上面写着“已经进行了修改,你想继续而不保存吗?取消或继续”:

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) 的编辑模式下启用,因此仅在手动取消编辑/创建或尝试在编辑/创建时更改联系人时,但由于splitView 在 iPad 和 iPhone 上的工作方式不同,而且在 iPhone 上,主视图似乎位于详细视图上方,UIControl 也在上方( iPhone 3D Debugging view),它会导致阻止所有屏幕上的交互,无论我点击哪里都会显示取消弹出窗口。

你们能否解释一下仅在 MasterView 显示而不是无处不在时启用/显示此 UIControl 的方法。谢谢。

【问题讨论】:

    标签: ios iphone swift uisplitviewcontroller uicontrol


    【解决方案1】:

    我最终在详细视图上使用了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
            }
        }
    

    它有效! :)

    【讨论】:

      猜你喜欢
      • 2020-08-04
      • 2011-02-16
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多