简体   繁体   English

iOS 按钮可点击但不可见

[英]iOS button is clickable but not visible

I have a view(let's call it scanView) that opens camera to scan for QR Codes.我有一个视图(我们称它为 scanView),可以打开相机扫描二维码。 I have placed a button on it which opens or closes the flash. The problem i am facing is that the button is getting clicked but it is not visible, i,e, I can turn flash on or off by clicking on screen where i placed the button, but the button is not visible.我在上面放了一个按钮,可以打开或关闭 flash。我面临的问题是按钮被点击但它不可见,即,我可以通过点击我放置的屏幕打开或关闭 flash按钮,但按钮不可见。 I checked the Alpha of button, tried bringing subview to front also.我检查了按钮的 Alpha,也尝试将子视图放在前面。 Nothing works.什么都不管用。 Is it some issue related to QR reader of iOS?是否与 iOS 的 QR 阅读器有关? Here is the implementation of QR Reader:下面是二维码阅读器的实现:

        captureSession = AVCaptureSession()

        guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else { return }
        let videoInput: AVCaptureDeviceInput

        do {
            videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
        } catch {
            return
        }

        if (captureSession.canAddInput(videoInput)) {
            captureSession.addInput(videoInput)
        } else {
            failed()
            return
        }

        let metadataOutput = AVCaptureMetadataOutput()

        if (captureSession.canAddOutput(metadataOutput)) {
            captureSession.addOutput(metadataOutput)

            metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
            metadataOutput.metadataObjectTypes = [.qr]
        } else {
            failed()
            return
        }

        previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
        previewLayer.frame = scanView.layer.bounds
        previewLayer.videoGravity = .resizeAspectFill
        
        scanView.layer.addSublayer(previewLayer)
        captureSession.startRunning()

查看层次结构调试器图像

As you can see above I have added a background color and background image too for clarity.正如您在上面看到的那样,为了清晰起见,我也添加了背景颜色和背景图像。 According to me the button looks fine in hierarchy.根据我的说法,按钮在层次结构中看起来很好。 On this scanView, I am adding the button from my xib file在这个 scanView 上,我从我的 xib 文件中添加按钮

First, it is not related to QR Reader implementation probably.首先,它可能与 QR Reader 实现无关。

Second, ask yourself how the button is supposed to be seen?其次,问问自己应该如何看待按钮? Title?标题? Image?图片?

Third, you can always press 'Debug View Hierarchy' button while running the app, to stop its execution and to see all the views present on the screen.第三,您始终可以在运行应用程序时按“调试视图层次结构”按钮,以停止其执行并查看屏幕上显示的所有视图。

'Debug View Hierarchy' button in on the same Debug Tools pane below where other debugging tools (like breakpoints) are placed. “调试视图层次结构”按钮位于放置其他调试工具(如断点)下方的同一调试工具窗格中。

Learn how to use Debug View Hierarchy , so you can clearly see where the button is on the screen and why it's not visible.了解如何使用Debug View Hierarchy ,这样您就可以清楚地看到按钮在屏幕上的位置以及它不可见的原因。

I think you have a problem with the image of the button because you are able to click on the button but are not able to see it, make sure the image is added properly on to the button.我认为您对按钮的图像有疑问,因为您可以单击按钮但看不到它,请确保图像已正确添加到按钮上。

Keep one thing in mind, that if it is clickable, then it is there, focus on its presentation.请记住一件事,如果它是可点击的,那么它就在那里,专注于它的呈现。 Also try to add a background color to it and remove the image, just to make sure your other implementation is working properly.还尝试为其添加背景颜色并删除图像,以确保您的其他实现正常工作。

I managed to solve the issue by setting the zposition of the button.我设法通过设置按钮的 zposition 解决了这个问题。 Thank you for your time everyone谢谢大家的宝贵时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM