ios - 自定义 UIButton 命中和 UIImagePickerController 按钮背景

标签 ios swift uibutton uiimagepickercontroller

我正在使用 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 的按钮中放置一些背景而不使用自定义选择器?

谢谢!

最佳答案

您可以在 hitTest 函数开始时执行此操作:

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

关于ios - 自定义 UIButton 命中和 UIImagePickerController 按钮背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46112082/

相关文章:

ios - SVProgressHUD 与 CocoaPods 不同版本

ios - SDWebImage 检查图像是否使用 Swift 缓存 : Ambiguous Reference

ios - 更改 UIButton 中标题的背景颜色

swift - 在 uibutton 上单击 UITableView 中的 reloadData - swift

swift - 为什么向 UICollectionViewCell 中的按钮添加操作效果不佳?

ios - 如何为 UITableView 设置分隔符的颜色

android - 如何使用/合并 CPP 文件到 Android 项目?

ios - MKOverlay 路线在 Apple Breadcrumb iOS 代码中工作,但在我的应用程序中不起作用

ios - 在 SWIFT 的 uitableview 中打印 Core Data 数据库

ios - Realm -iOS : Model object becomes nil when it's added to realm