PictureViewController.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // Test3ViewController.swift
  3. // MCPlus
  4. //
  5. // Created by seo ha on 30/01/2019.
  6. // Copyright © 2019 KangSH. All rights reserved.
  7. //
  8. import UIKit
  9. import Photos
  10. import ReactiveCocoa
  11. import ReactiveSwift
  12. class PictureViewController: UIViewController {
  13. @objc var callBack:(([String:String])->Void)?
  14. var user:User?
  15. @IBOutlet weak var cameraContainer: UIView!
  16. @IBOutlet weak var gallaryContainer: UIView!
  17. static var patientId = MutableProperty<String?>(nil)
  18. static var patientNm = MutableProperty<String?>(nil)
  19. static var ageGender = MutableProperty<String?>(nil)
  20. }
  21. extension PictureViewController{
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. if let testData = "{\"hospitalCD\":\"1000001\",\"patientId\":\"김길동\",\"userId\":\"20\",\"patientNm\":\"M\",\"age\":\"M\",\"gender\":\"M\",\"deptCd\":\"M\",\"deptNm\":\"M\",\"doctorId\":\"M\",\"doctorNm\":\"M\",\"treatCls\":\"M\"}".data(using: .utf8){
  25. user = try? JSONDecoder().decode(User.self, from: testData)
  26. print(user)
  27. }
  28. PictureViewController.patientId.value = user?.patientId
  29. PictureViewController.patientNm.value = user?.patientNm
  30. PictureViewController.ageGender.value = "\(user?.age ?? "") / \(user?.gender ?? "")"
  31. }
  32. func scanAction(){
  33. let alert = UIAlertController(title: "선택하세요", message: "", preferredStyle: .actionSheet)
  34. alert.addAction(UIAlertAction(title: "카메라", style: .default, handler: self.cameraAction))
  35. alert.addAction(UIAlertAction(title: "갤러리", style: .default, handler: self.gallaryAction))
  36. // show action sheet
  37. if let popoverController = alert.popoverPresentationController {
  38. popoverController.sourceView = self.view
  39. popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
  40. popoverController.permittedArrowDirections = []
  41. }
  42. self.present(alert, animated: true, completion: nil)
  43. }
  44. //커스텀 카메라 호출
  45. func cameraAction(action:UIAlertAction?){
  46. self.cameraContainer.isHidden = false
  47. self.gallaryContainer.isHidden = true
  48. }
  49. //포토 갤러리 호출
  50. func gallaryAction(action:UIAlertAction?){
  51. self.cameraContainer.isHidden = true
  52. self.gallaryContainer.isHidden = false
  53. }
  54. }