2015-10-21 26 views
0

我正在创建自己的UIImagePicker叠加层,并使用Xib来显示叠加层。每当我呈现imagepicker,它似乎呈现两次,一次当我调用主包加载笔尖,另一次当我明确地呈现imagepickercontroller。我遇到的主要问题是,当我放弃imagepickercontroller时,第一个问题很好,但是xib的底层视图仍然存在,不管我做什么都不去。我如何摆脱提出后xib?

我试图转换Objective-C示例项目,以了解如何创建Apple在其网站上将自定义uiimagepickercontroller转换为Swift。我不知道我的“M做错了,这里是我的代码:

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) 
} 

这里是在厦门国际银行的按钮驳回视图的代码我怎样才能解决这个问题,因为我打印出来?导航堆栈视图控制器的阵列,并且只显示一个。

@IBAction func goBack(sender: AnyObject) { 
    self.imagePickerController.dismissViewControllerAnimated(true, completion: nil) 
} 
+1

在你的XI B文件,你有什么网点连接到文件的所有者? –

+0

非常感谢这个问题,我意识到我已经将视图连接到文件所有者以及视图控制器中的一个变量。我希望我能给你复选标记,但你刚刚治愈了我的头痛! – Jay

+0

这只是一个预感,我会发布一个答案,所以你可以标记它。 –

回答

1

这听起来像你有你的视图控制器的view插座连接到视图中您的.xib文件除了overlayView插座。这可能会导致你所描述的内容。