Browse Source

take photo

Chris 5 years ago
parent
commit
db977745df
17 changed files with 230 additions and 7 deletions
  1. 116 7
      RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishTakePhoto/PublishTakePhotoController.swift
  2. 4 0
      RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishViewController.swift
  3. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_pause.imageset/Contents.json
  4. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_pause.imageset/video_btn_pause@2x.png
  5. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_pause.imageset/video_btn_pause@3x.png
  6. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight.imageset/Contents.json
  7. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight.imageset/video_ico_flashlight@2x.png
  8. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight.imageset/video_ico_flashlight@3x.png
  9. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_auto.imageset/Contents.json
  10. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_auto.imageset/video_ico_flashlight_auto@2x.png
  11. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_auto.imageset/video_ico_flashlight_auto@3x.png
  12. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_close.imageset/Contents.json
  13. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_close.imageset/video_ico_flashlight_close@2x.png
  14. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_close.imageset/video_ico_flashlight_close@3x.png
  15. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_overturn.imageset/Contents.json
  16. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_overturn.imageset/video_ico_overturn@2x.png
  17. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_overturn.imageset/video_ico_overturn@3x.png

+ 116 - 7
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishTakePhoto/PublishTakePhotoController.swift

@@ -11,11 +11,23 @@ import RxSwift
 import JXSegmentedView
 import AliyunVideoSDKPro
 
+enum FlashType : Int {
+    case close = 0
+    case open = 1
+    case auto = 2
+}
+
 class PublishTakePhotoController: BaseViewController {
     
+    typealias DismissClosure = () -> Void
+    var dismissClosure: DismissClosure?
+    
+    var curFlashType : FlashType! = .close
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         setupViews()
+        setupLayouts()
     }
     
     override func viewWillAppear(_ animated: Bool) {
@@ -25,25 +37,122 @@ class PublishTakePhotoController: BaseViewController {
     override func viewWillDisappear(_ animated: Bool) {
         navigationBar.isHidden = false
         recorder.destroy()
-        
     }
+    
     override func setupViews() {
-        
+        view.addSubview(backButton)
+        view.addSubview(reverseButton)
+        view.addSubview(flashButton)
+        view.addSubview(photoButton)
         
     }
     
-    private lazy var recorder: AliyunIRecorder = {
+    override func setupLayouts() {
+        backButton.snp.makeConstraints { (make) in
+            make.top.equalTo(23)
+            make.left.equalTo(5)
+            make.width.equalTo(40)
+            make.height.equalTo(40)
+        }
         
+        reverseButton.snp.makeConstraints { (make) in
+            make.top.equalTo(86)
+            make.right.equalTo(-12)
+            make.width.equalTo(40)
+            make.height.equalTo(44)
+        }
+        reverseButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 6)
         
-        let recorder = AliyunIRecorder.init(delegate: self as? AliyunIRecorderDelegate, videoSize: CGSize(width: 720, height: 1280))
+        flashButton.snp.makeConstraints { (make) in
+            make.top.equalTo(reverseButton.snp_bottom).offset(20)
+            make.centerX.equalTo(reverseButton.snp_centerX)
+            make.width.equalTo(40)
+            make.height.equalTo(46)
+        }
+        flashButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
         
-        // 预览视图,必须设置
+        photoButton.snp.makeConstraints { (make) in
+            make.bottom.equalTo(-kSafeTabBarHeight-68)
+            make.centerX.equalToSuperview()
+            make.size.equalTo(79)
+        }
+    }
+    
+    private lazy var recorder: AliyunIRecorder = {
+        let recorder = AliyunIRecorder.init(delegate: self as? AliyunIRecorderDelegate, videoSize: CGSize(width: 720, height: 1280))
         recorder?.preview = self.view;
-        
-        
         return recorder!
     }()
     
+    private lazy var backButton: UIButton = {
+        let backButton = UIButton(type: UIButton.ButtonType.custom)
+        backButton.setImage(kImage(name: "navbar_back_white"), for: UIControl.State.normal)
+        backButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let dismissClosure = self?.dismissClosure {
+                dismissClosure()
+            }            
+        }).disposed(by: disposeBag)
+        return backButton
+    }()
+    
+    private lazy var reverseButton: UIButton = {
+        let reverseButton = UIButton(type: UIButton.ButtonType.custom)
+        reverseButton.setImage(kImage(name: "video_ico_overturn"), for: UIControl.State.normal)
+        reverseButton.setTitle("翻转", for: UIControl.State.normal)
+        reverseButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        reverseButton.titleLabel?.font = kRegularFont12
+        reverseButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            self?.recorder.switchCameraPosition()
+            
+        }).disposed(by: disposeBag)
+        return reverseButton
+    }()
+    
+    private lazy var flashButton: UIButton = {
+        let flashButton = UIButton(type: UIButton.ButtonType.custom)
+        switch curFlashType {
+        case .open?:
+            flashButton.setImage(kImage(name: "video_ico_flashlight"), for: UIControl.State.normal)
+        case .auto?:
+            flashButton.setImage(kImage(name: "video_ico_flashlight_auto"), for: UIControl.State.normal)
+        default:
+            flashButton.setImage(kImage(name: "video_ico_flashlight_close"), for: UIControl.State.normal)
+        }
+        flashButton.setTitle("闪光灯", for: UIControl.State.normal)
+        flashButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        flashButton.titleLabel?.font = kRegularFont12
+        flashButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            switch self?.curFlashType {
+            case .open?:
+                self?.curFlashType = FlashType.auto
+                flashButton.setImage(kImage(name: "video_ico_flashlight_auto"), for: UIControl.State.normal)
+                self?.recorder.switchTorch(with: AliyunIRecorderTorchMode.auto)
+            case .auto?:
+                self?.curFlashType = FlashType.close
+                flashButton.setImage(kImage(name: "video_ico_flashlight_close"), for: UIControl.State.normal)
+                self?.recorder.switchTorch(with: AliyunIRecorderTorchMode.off)
+            default:
+                self?.curFlashType = FlashType.open
+                flashButton.setImage(kImage(name: "video_ico_flashlight"), for: UIControl.State.normal)
+                self?.recorder.switchTorch(with: AliyunIRecorderTorchMode.on)
+            }
+            
+        }).disposed(by: disposeBag)
+        return flashButton
+    }()
+    
+    private lazy var photoButton: UIButton = {
+        let photoButton = UIButton(type: UIButton.ButtonType.custom)
+        photoButton.setImage(kImage(name: "video_btn_shoot"), for: UIControl.State.normal)
+        photoButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            self?.recorder.takePhoto({ (image, rawImage) in
+                print("----\n")
+                print(image as Any)
+            })
+        }).disposed(by: disposeBag)
+        return photoButton
+    }()
+    
 }
 
 extension PublishTakePhotoController : JXSegmentedListContainerViewListDelegate {

+ 4 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishViewController.swift

@@ -173,6 +173,10 @@ extension PublishViewController :JXSegmentedListContainerViewDataSource {
             return videoVc        
         default:
             let photoVc = PublishTakePhotoController()
+            photoVc.dismissClosure = {
+                [weak self] in
+                self?.dismiss(animated: true, completion: nil)
+            }
             return photoVc
         }
     }

+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_pause.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_btn_pause@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_btn_pause@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_pause.imageset/video_btn_pause@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_pause.imageset/video_btn_pause@3x.png


+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_flashlight@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_flashlight@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight.imageset/video_ico_flashlight@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight.imageset/video_ico_flashlight@3x.png


+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_auto.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_flashlight_auto@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_flashlight_auto@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_auto.imageset/video_ico_flashlight_auto@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_auto.imageset/video_ico_flashlight_auto@3x.png


+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_close.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_flashlight_close@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_flashlight_close@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_close.imageset/video_ico_flashlight_close@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_flashlight_close.imageset/video_ico_flashlight_close@3x.png


+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_overturn.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_overturn@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_overturn@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_overturn.imageset/video_ico_overturn@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_overturn.imageset/video_ico_overturn@3x.png