我正在尝试在ImagePicker上创建一个叠加层,并发现我可以通过编程方式创建UIView,但我更喜欢使用我可以在Storyboard中操作的UIView。
从下面的代码片段中可以看出,我已经将UIImagePickerControllerDelegate分配给了我的ViewController,创建了图像选择器,并且有一个方法来分配我想要的叠加视图。如果我尝试引用UIView,它是与故事板中存在的UIView相关联的出口,则不会出现。如果If以编程方式创建它,那一切都很好。如何将它分配给我想在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
}
答案 0 :(得分:0)
初始化在界面构建器中创建的视图时,您需要使用NSBundle.mainBundle().loadNibNamed()
查看this answer如何执行此操作。