Blame view

Twear/Basic/View/ShareView.swift 4.67 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  //
  //  ZCAlertView.swift
  //  zc
  //
  //  Created by wyp on 2020/11/4.
  //  Copyright © 2020 wyp. All rights reserved.
  //
  
  import UIKit
  import MBProgressHUD
  import SwiftUI
  
  class ShareView: UIView {
      
      typealias clickAlertClosure = (_ index: Int) -> Void
      var clickClosure: clickAlertClosure!
      var shareImage: UIImage?
      
      @IBOutlet private weak var bgView: UIView!
      
      private let platformArray: [SSDKPlatformType] = [.subTypeWechatSession, .subTypeWechatTimeline, .typeQQ, .subTypeQZone, .typeSinaWeibo, .typeFacebook, .typeInstagram, .typeWhatsApp]
      
      override init(frame: CGRect) {
          super.init(frame: frame)
          initFromNib()
          setupUI()
      }
      
      required init?(coder: NSCoder) {
          super.init(coder: coder)
          initFromNib()
          setupUI()
      }
      
      private func initFromNib() {
          if let view = Bundle.main.loadNibNamed("ShareView", owner: self, options: nil)?.first as? UIView {
              view.frame = bounds
              self.addSubview(view)
          }
      }
      
      
      init(_ image: UIImage?) {
          super.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
          self.shareImage = image
          initFromNib()
          setupUI()
      }
      
      func setupUI() {
          bgView.layoutIfNeeded()
582f536d   yangbin   common:2022.1.28
52
          self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(clickView(_:))))
75d24c15   yangbin   123
53
54
55
56
          bgView.setCorners(corners: [.topLeft, .topRight], radio: 15)
      }
      
      
582f536d   yangbin   common:2022.1.28
57
58
59
60
61
62
      @objc private func clickView(_ gestureRecognizer: UITapGestureRecognizer) {
          dismiss()
      }
      
      
      
75d24c15   yangbin   123
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  
      @IBAction func clickBtnAction(_ sender: UIButton) {
          if (clickClosure != nil) {
              clickClosure!(sender.tag)
          }
          
          if sender.tag == 10 {
              dismiss()
          } else {
              checkInstalled(sender.tag)
          }
      }
      
      func checkInstalled(_ index: Int) {
          if ShareSDK.isClientInstalled(platformArray[index]) {
              getImage(index)
          } else {
be19e595   yangbin   9
80
              MBProgressHUD.showh(LocString("未安装该应用"))
75d24c15   yangbin   123
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
          }
      }
      
      func getImage(_ index: Int) {
          if let image = shareImage {
              share(index, image: image)
          } else {
              SSEShareHelper.screenCaptureShare {[weak self] sImage, handler in
                  if let sImage = sImage {
                      
                      sImage.getNativeImage { image in
                          if let image = image {
                              self?.share(index, image: image)
                          }
                      }
                     
                  }
              } onStateChanged: { _, _, _, _ in
                  
              }
          }
      }
      
      func share(_ index: Int, image: UIImage) {
          let shareParameters = NSMutableDictionary()
          shareParameters.ssdkSetupShareParams(byText: "", images: image, url: nil, title: "", type: .image)
          ShareSDK.share(platformArray[index], parameters: shareParameters) { responseState, dic, entity, error in
              if responseState == .success {
be19e595   yangbin   9
109
110
111
112
                  if let curVC = UIViewController.getCurrentViewController() {
                      curVC.showAlert(title: "", message: LocString("分享成功"), cancelText: nil, confirm: nil)
                  }
  //                MBProgressHUD.showh(LocString("分享成功"))
75d24c15   yangbin   123
113
              } else if responseState == .fail {
be19e595   yangbin   9
114
115
116
117
118
                  if let curVC = UIViewController.getCurrentViewController() {
                      curVC.showAlert(title: "", message: LocString("分享失败"), cancelText: nil, confirm: nil)
                  }
  //                MBProgressHUD.showh(LocString("分享失败"))
  //                print("分享失败\(index)")
75d24c15   yangbin   123
119
120
121
122
              }
              self.dismiss()
          }
      }
582f536d   yangbin   common:2022.1.28
123
        
75d24c15   yangbin   123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
      
      func show() {
          let wind = KeyWindow
          self.alpha = 0
          
          wind.addSubview(self)
          UIView.animate(withDuration: 0.25, animations: { () -> Void in
              self.alpha = 1
          })
      }
      
      @objc func dismiss() {
          MBProgressHUD.hide()
          UIView.animate(withDuration: 0.25, animations: { () -> Void in
              self.alpha = 0
          }, completion: { (finish) -> Void in
              if finish {
                  self.removeFromSuperview()
              }
          })
      }
      
      deinit {
          print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
      }
  //
  //    required init?(coder aDecoder: NSCoder) {
  //        fatalError("init(coder:) has not been implemented")
  //    }
  //
  
      /*
      // Only override draw() if you perform custom drawing.
      // An empty implementation adversely affects performance during animation.
      override func draw(_ rect: CGRect) {
          // Drawing code
      }
      */
  
  }