有谁知道手机屏幕顶部到相机中图像预览开始之间的距离(以像素为单位)?

时间:2015-02-07 11:23:33

标签: ios xcode uiimagepickercontroller

我正在尝试构建自定义相机叠加层,并且需要在拍摄照片时知道图像预览正上方黑色工具栏的高度。有谁知道这个?图片如下:

enter image description here

1 个答案:

答案 0 :(得分:1)

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

制作递归视图记录功能,例如......

    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视图及其各自框架的精美打印输出。