2014-10-03 64 views
0

所以我遇到了我的相機凍結問題。當它被稱爲第一次它工作得很好。並在按鈕上顯示我的圖像。但是,如果我再回到同一個按鈕來重新調用相機或調用相機的頁面上的任何其他按鈕,它會啓動相機,但不是黑屏。相機實際上並沒有出現。這裏是我使用的代碼...幫助會很好。Ios,相機在啓動時凍結(黑屏)

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!) { 


    let image = info[UIImagePickerControllerOriginalImage] as UIImage 
    pickedImage = image 

    if let buttonToSet = buttonToSet { 
     switch buttonToSet { 
     case .Button1 : 
      p1Image = pickedImage 
      p1ImageButton.setImage(pickedImage, forState: UIControlState.Normal) 
     case .Button2 : 
      p2Image = pickedImage 
      p2ImageButton.setImage(pickedImage, forState: UIControlState.Normal) 
     case .Button3 : 
      p3Image = pickedImage 
      p3ImageButton.setImage(pickedImage, forState: UIControlState.Normal) 
     case .Button4 : 
      p4Image = pickedImage 
      p4ImageButton.setImage(pickedImage, forState: UIControlState.Normal) 

     } 
    } 


    self.dismissViewControllerAnimated(true, completion: nil) 
    scrollView.setContentOffset(CGPointMake(0, -65), animated: true) 


} 

func imagePickerControllerDidCancel(picker: UIImagePickerController) { 
    dismissViewControllerAnimated(true, completion: nil) 
    scrollView.setContentOffset(CGPointMake(0, -65), animated: true) 
} 

func promptForSource(){ 
    let actionSheet = UIActionSheet(title: "Image Source", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles: "Camera", "Photo Roll") 

    actionSheet.showInView(self.view) 

} 

func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int) { 
    if buttonIndex != actionSheet.cancelButtonIndex { 

     if buttonIndex != actionSheet.firstOtherButtonIndex { 

      promptForCamera() 
     } 
     else{ 
      promptForPhotoRoll() 
     } 

    } 
} 

func promptForCamera(){ 
    let controller = UIImagePickerController() 
    controller.sourceType = UIImagePickerControllerSourceType.Camera 
    controller.delegate = self 
    presentViewController(controller, animated: true, completion: nil) 
} 

func promptForPhotoRoll(){ 
    let controller = UIImagePickerController() 
    controller.sourceType = UIImagePickerControllerSourceType.PhotoLibrary 
    controller.delegate = self 
    presentViewController(controller, animated: true, completion: nil) 
} 


@IBAction func p1PhotoTapped(sender: AnyObject) { 
    buttonToSet = .Button1 

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){ 
     promptForSource() 



    }else{ 
     promptForPhotoRoll() 
    } 


} 


@IBAction func p2PhotoTapped(sender: AnyObject) { 
    buttonToSet = .Button2 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){ 
     promptForSource() 



    }else{ 
     promptForPhotoRoll() 
    } 

} 


@IBAction func p3PhotoTapped(sender: AnyObject) { 
    buttonToSet = .Button3 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){ 
     promptForSource() 



    }else{ 
     promptForPhotoRoll() 
    } 

} 

@IBAction func p4PhotoTapped(sender: AnyObject) { 
    buttonToSet = .Button4 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){ 
     promptForSource() 



    }else{ 
     promptForPhotoRoll() 
    } 

} 

回答

1

我想出了問題,不是代碼問題,而是電話問題。在關閉手機後再備份後,我能夠解決問題。