ios - UIButton 超出 View Controller 而没有裁剪到其边界

标签 ios swift uibutton

在我的应用程序中,我从这里使用 KYDrawerController 库:https://github.com/ykyouhei/KYDrawerController

它按预期工作,但我想在菜单 View Controller (打开时位于顶部)上添加一个 UIButton,但它被 View 边界裁剪了。我可以通过向您展示屏幕截图来解释这一点的最佳方式:

enter image description here

它应该是这样的:

enter image description here

按钮现在有负的右约束边距,所以它的位置是正确的,但我怎样才能禁用剪裁?

在你可以在前台看到的菜单 View Controller 中,我添加了以下代码:

    self.navigationController?.navigationBar.clipsToBounds = false
    self.navigationController?.view.clipsToBounds = false
    self.view.clipsToBounds = false
    let elDrawer = self.navigationController?.parent as! KYDrawerController
    elDrawer.view.clipsToBounds = false
    elDrawer.displayingViewController?.view.clipsToBounds = false
    elDrawer.drawerViewController?.view.clipsToBounds = false
    elDrawer.displayingViewController?.view.clipsToBounds = false
    elDrawer.mainViewController.view.clipsToBounds = false
    elDrawer.inputViewController?.view.clipsToBounds = false
    elDrawer.splitViewController?.view.clipsToBounds = false

如您所见,我已经尝试了所有可能的方法来禁用裁剪,但它仍然被裁剪了。我怎样才能做到这一点?

编辑: 添加了层次结构 View : enter image description here

我还尝试运行以下测试:

var view = arrowButton as UIView?
        repeat {
            view = view?.superview
            if let sview = view {
                if(sview.clipsToBounds){
                    print("View \(view) clips to bounds")
                    break
                }
                else{
                    print("View \(view) does not clip to bounds")
                }
            }
        } while (view != nil)

它打印:

View Optional(>) does not clip to bounds

所以看起来没有任何东西被裁剪但它被裁剪了。

编辑2: 调试 View 层次结构: enter image description here

最佳答案

是的,我找到了解决方案:

self.navigationController?.view.subviews[0].clipsToBounds = false

不需要旧代码。

UINavigationTransitionView(它是 Apple 私有(private)类)负责打开 clipToBounds。

关于ios - UIButton 超出 View Controller 而没有裁剪到其边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41396052/

相关文章:

ios - 检查当前屏幕在 iOS 中是打开还是关闭

ios - 使用结构体时不断收到 "Cannot assign to value: 'calculateBMI' is a method"

ios - 针对特定情况获取两个发件人值而不是一个值?

ios - 如何从 ActionSheet 更改 UIButton 的文本

ios - 删除记录成功但无法打印消息

ios - 如何从 iOS 发送上游 FCM 消息?

ios - Mapkit 中的 OSM 与 Route-me OSM

ios - [cell addSubview :button] and [cell. contentview addsubview:button] 之间有什么区别

ios - 将 JSON 结果的 setValue(纬度/经度坐标为 Double)设置为 Swift 中的 CoreData

ios - 如何使用 UITableViews 通过 Swift 创建静态和动态行