我正在创建自己的UIImagePicker Overlay并使用Xib来显示叠加层。每当我呈现imagepicker时,它似乎呈现两次,一次当我调用主包来加载nib时,另一次当我明确地呈现imagepickercontroller时。我遇到的主要问题是当我关闭imagepickercontroller时,第一个问题就出现了,这很好,但xib的基础视图仍然存在,并且不管我做什么都不行。
我尝试转换Objective-C示例项目,以了解如何在他们的网站上创建自定义uiimagepickercontroller到Swift。我不确定我做错了什么,这是我的代码:
func showImagePickerForSourceType(sourceType: UIImagePickerControllerSourceType) {
let picker = UIImagePickerController()
picker.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
picker.sourceType = sourceType
picker.delegate = self
if sourceType == UIImagePickerControllerSourceType.Camera {
//gets rid of the out of the box imagepicker
picker.showsCameraControls = false
//loads the overlay xib for the camera
NSBundle.mainBundle().loadNibNamed("OverlayView", owner: self, options: nil)
self.overlayView.frame = (picker.cameraOverlayView?.frame)!
picker.cameraOverlayView = self.overlayView
self.overlayView = nil
//makes the image capture screen the full screen size
let screenSize: CGSize = UIScreen.mainScreen().bounds.size
let cameraAspectRatio: Float = 4.0 / 3.0
let imageWidth:Float = floorf(Float(screenSize.width) * cameraAspectRatio)
let scale: Float = ceilf((Float(screenSize.height + 120) / imageWidth) * 10.0) / 10.0
picker.cameraViewTransform = CGAffineTransformMakeScale(CGFloat(scale), CGFloat(scale))
}
self.imagePickerController = picker
self.presentViewController(self.imagePickerController, animated: true, completion: nil)
}
以下是xib上关闭视图的按钮的代码。我怎样才能解决这个问题?因为我打印出导航堆栈上的视图控制器数组,它只显示一个。
@IBAction func goBack(sender: AnyObject) {
self.imagePickerController.dismissViewControllerAnimated(true, completion: nil)
}
答案 0 :(得分:1)
听起来您的视图控制器的view
插座已连接到.xib文件中的视图以及overlayView
插座。这可能会导致你所描述的内容。