0
카메라 얼어 버리는 문제가 있습니다. 그것이 처음으로 불릴 때 그것은 잘 작동합니다. 버튼에 내 이미지를 표시합니다. 그러나 카메라를 다시 호출하기 위해 같은 버튼으로 돌아 가거나 카메라를 호출하는 페이지의 다른 버튼을 누르면 카메라가 켜지지만 검은 색 화면이 아닙니다. 카메라가 실제로 나타나지 않습니다. 여기 내가 사용하고있는 코드는 ... 도움이 될 것입니다.시작시 카메라 얼어 짐 (검은 색 화면)
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()
}
}