【问题标题】:Custom UIButton hit and UIImagePickerController buttons background自定义 UIButton hit 和 UIImagePickerController 按钮背景
【发布时间】:2017-09-08 08:32:09
【问题描述】:

我正在使用 UIButton 的这个扩展,女巫忽略按钮透明颜色的点击

open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
    if (!self.bounds.contains(point)) {
        return nil
    }
    else {
        let color : UIColor = self.getColourFromPoint(point: point)
        let alpha = color.cgColor.alpha;
        if alpha <= 0.0 {
            debugPrint("no tocado")
            return nil
        }
        return self
    }
}

当我调用 UIImagePickerController 时,按钮只有透明背景的文本,很难点击它们...

有一些方法可以检测按钮的上下文以避免 UIImagePickerController 中的这种扩展? 或者在没有自定义选择器的情况下在 UIImagePickerController 的按钮中放置一些背景?

谢谢!

【问题讨论】:

  • 不清楚你在问什么。请尝试再次解释。
  • 完成了,我有一个 UIbuttons 的扩展,但我想避免在 Camera ty 的 uiimagepickercontroller 中出现这种行为!
  • 我更新了我的答案。你能检查一下这是否对你有帮助吗?

标签: ios swift uibutton uiimagepickercontroller


【解决方案1】:

您可以在 hitTest 函数的开头执行此操作:

if self.isKind(of: UIImagePickerController.self){
    return nil
}

【讨论】:

  • 不,不起作用,按钮是 UIButton 类型,但我需要知道从 wwitch 类 /context 被调用
  • @User22 我感觉你为一个简单的问题做了一些非常复杂的事情。你要存档什么?为什么按钮的 alpha = 0 而不仅仅是隐藏?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-19
  • 1970-01-01
  • 1970-01-01
  • 2016-04-07
相关资源
最近更新 更多