我正在尝试在 ImagePicker 之上创建覆盖,并发现我可以通过编程方式创建 UIView,但更喜欢使用可以在 Storyboard 中操作的 UIView。
正如您从下面的代码截图中看到的那样,我已经将 UIImagePickerControllerDelegate 分配给了我的 ViewController,创建了图像选择器,并有一个方法来分配我想要的覆盖视图。如果我尝试引用作为与故事板中存在的 UIView 相关联的插座的 UIView,它不会出现。如果如果以编程方式创建它,一切都很好。如何将它分配给我想在 Storyboard 中拖放控件的 UIView?
提前感谢您的任何建议/指导。
干杯,卡尔
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
// UIView for telemetry data
@IBOutlet weak var telemetryPanel: UIView!
...
override func viewDidAppear(animated:bool) {
...
let cameraImagePicker = UIImagePickerController()
...
// Call method to create a custom overlay for the camera
cameraImagePicker.cameraOverlayView = self.customViewForImagePicker(cameraImagePicker)
}
func customViewForImagePicker(imagePicker: UIImagePickerController!) -> UIView {
// TODO: - Assigning the view to the telemetry panel does not work
// let view:UIView = self.telemetryPanel
// view.backgroundColor = UIColor.whiteColor()
// view.alpha = 0.25
// return view
// Creating the view programmatically overlays it
let cameraAspectRatio:CGFloat = 4.0 / 3.0;
let screenSize = UIScreen.mainScreen().bounds.size
let imageWidth = floorf(Float(screenSize.width) * Float(cameraAspectRatio))
let view: UIView = UIView(frame: CGRectMake(0, screenSize.height-65, CGFloat(imageWidth), 65))
view.backgroundColor = UIColor.whiteColor()
view.alpha = 0.25
return view
}