2017-02-23 4 views
-4

카메라 나 imageGallery를 열기 위해이 두 개의 별도 버튼을 사용하고 있습니다. enter image description hereUIImagePickerController .savedPhotosAlbum 대신 .camera로 엽니 다.

@IBAction func tapGal(_ sender: Any) { 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum) { 
     let imagePicker = UIImagePickerController() 
     imagePicker.delegate = self 
     imagePicker.sourceType = UIImagePickerControllerSourceType.camera 
     imagePicker.allowsEditing = true 

     self.present(imagePicker, animated: true, completion: nil) 

    } else { 
     NSLog("No Cam Fam") 
    } 
} 

@IBAction func tapCam(_ sender: Any) { 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) { 
     let imagePicker = UIImagePickerController() 
     imagePicker.delegate = self 
     imagePicker.sourceType = UIImagePickerControllerSourceType.camera 
     imagePicker.allowsEditing = true 

     self.present(imagePicker, animated: true, completion: nil) 

    } else { 
     NSLog("No Cam Fam") 
    } 
} 

카메라 버튼은 카메라를 엽니 다 의미, 그냥 정상적으로 작동하고 있지만, 갤러리 버튼은 카메라를 열어 가고 있습니다. 갤러리 버튼이 실제로 tapGal 기능에 연결되어 있는지 확인하기 위해 다시 확인했습니다. 또한 .savedPhotosAlbum.photoLibrary으로 바꾸려고 시도했지만 그 결과는 같습니다.

+4

제발 봐라. 통해 UR 코드. 두 개의'imagePicker.sourceType = ...'줄을보십시오. – rmaddy

+1

코드가 동일하므로 결과가 동일합니다. –

답변

1

imagePicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum에 새로운 하나를 당신의 방법을 대체하려고 변경할 필요가 있었다.

당신의 실수는 당신이 두 방법에 대한 코드의 같은 라인을 통과한다 :

imagePicker.sourceType = UIImagePickerControllerSourceType.camera 

instad

imagePicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum 

의 당신의 하나 방법 아래 바꾸기 : -

@IBAction func tapGal(_ sender: Any) { 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum) { 
     let imagePicker = UIImagePickerController() 
     imagePicker.delegate = self 
     imagePicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum 



     imagePicker.allowsEditing = true 

     self.present(imagePicker, animated: true, completion: nil) 

    } else { 
     NSLog("No PhotoLibrary") 
    } 
} 
0

@rmaddy가 지적한 간단한 수정. 나는 imagePicker.sourceType = UIImagePickerControllerSourceType.camera

2
@IBAction func tapGal(_ sender: Any) { 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType. photoLibrary) { 
     let imagePicker = UIImagePickerController() 
     imagePicker.delegate = self 
     imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary // use PhotoLibrary, not camera 
     imagePicker.allowsEditing = true 

     self.present(imagePicker, animated: true, completion: nil) 

    } else { 
     NSLog("No Cam Fam") 
    } 
} 

@IBAction func tapCam(_ sender: Any) { 
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) { 
     let imagePicker = UIImagePickerController() 
     imagePicker.delegate = self 
     imagePicker.sourceType = UIImagePickerControllerSourceType.camera 
     imagePicker.allowsEditing = true 

     self.present(imagePicker, animated: true, completion: nil) 

    } else { 
     NSLog("No Cam Fam") 
    } 
} 
+0

코드 전용 답변은 겉만 번거롭게 작성되었습니다. 잘못된 점과 코드가 문제를 해결하는 방법에 대한 설명을 포함하십시오. 그게 더 좋은 대답입니다. – rmaddy