我正在尝试构建自定义相机覆盖图,并且需要在拍摄照片时知道图像预览上方黑色工具栏的高度。有人知道吗?下图:

最佳答案

您可以通过记录感兴趣的视图层次结构来找到问题的答案。

制作一个递归视图日志记录功能,类似...

    func logsubviews(view: UIView, indent: Int)->Void {
             //indenting
            var indent = indent + 1
            var indentString = ""
            for i in 0..<indent {
                indentString = " \(indentString)"
            }
            //logging
            println("\(indentString) \(view)")
            for subview in view.subviews {
                self.logsubviews(subview as UIView, indent: indent)
            }
        }

呈现后,然后记录imagePicker的视图层次结构:
@IBAction func invokeImagePicker(sender: AnyObject) {
        let imagePicker =  UIImagePickerController()
        imagePicker.sourceType = .Camera
        imagePicker.delegate = self
        self.presentViewController(imagePicker, animated: true, completion:{
            ()->Void in
            self.logsubviews(imagePicker.view, indent: 0)
        })
    }

您将很好地打印出imagePickerController的视图及其各自的框架。

关于ios - 有谁知道手机屏幕顶部到相机中图像预览开始之间的距离(以像素为单位)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28381529/

10-09 09:39