2015-10-21 37 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插座。這可能會導致你所描述的內容。