Commit 719707b3 authored by Steven杜宇's avatar Steven杜宇

// plan

parent ebdd487b
......@@ -7,6 +7,8 @@
//
import UIKit
import Photos
import VisualEffectView
class YHPlanPolicyImageInfo {
var model: YHPlanCaseModel = YHPlanCaseModel()
......@@ -54,10 +56,12 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
return collectView
}()
lazy var blurView: UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: .light) // 可以选择不同的模糊样式
let blurEffectView = UIVisualEffectView(effect: blurEffect)
return blurEffectView
lazy var blurView: VisualEffectView = {
let blurView = VisualEffectView()
blurView.colorTint = UIColor(hex: 0xAFAFAF).withAlphaComponent(0.15)
blurView.blurRadius = 16
blurView.scale = 1
return blurView
}()
lazy var shareBtn: UIButton = {
......@@ -73,6 +77,24 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
@objc func didShareBtnClicked() {
let view = YHPlanLinkShareView.alertView()
view.clickBlock = { [weak self] type in
guard let self = self else { return }
if 0 <= currentIndex, currentIndex < arr.count {
let model = arr[currentIndex]
if type == .wechat {
sendImageToWechat(model.img_url)
} else if type == .copyLink {
let pasteBoard = UIPasteboard.general
pasteBoard.string = model.img_url
YHHUD.flash(message: "复制成功")
} else if type == .saveImg {
saveImgFromUrl(model.img_url)
}
}
}
view.show()
}
......@@ -195,3 +217,60 @@ extension YHPlanPolicyDetailViewController: UIScrollViewDelegate {
}
}
extension YHPlanPolicyDetailViewController {
func saveImgFromUrl(_ urlString: String) {
guard let url = URL(string: urlString) else {
YHHUD.flash(message: "保存失败")
return
}
YHHUD.show(.progress(message: "下载中..."))
let task = URLSession.shared.dataTask(with: url) { data, _, error in
DispatchQueue.main.async {
YHHUD.hide()
guard let data = data, error == nil else { return YHHUD.flash(message: "保存成功") }
let image = UIImage(data: data)
if let image = image {
// 保存图片到图库
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAsset(from: image)
}, completionHandler: { success, error in
if success {
// 图片保存成功
DispatchQueue.main.async {
YHHUD.flash(message: "保存成功")
}
} else if let error = error {
// 保存失败
DispatchQueue.main.async {
YHHUD.flash(message: "保存失败")
}
print("保存图片出错: \(error.localizedDescription)")
}
})
}
}
}
task.resume()
}
func sendImageToWechat(_ urlString: String) {
guard let url = URL(string: urlString) else {
return
}
let task = URLSession.shared.dataTask(with: url) { data, _, error in
DispatchQueue.main.async {
guard let data = data, error == nil else { return }
let image = UIImage(data: data)
if let image = image {
YHShareManager.shared.sendImageContent(image)
}
}
}
task.resume()
}
}
......@@ -111,6 +111,34 @@ class YHPlanShareViewController: YHBaseViewController {
lazy var bottomShareView: YHPlanShareView = {
let v = YHPlanShareView(frame: .zero)
v.type = .link
v.clickBlock = { [weak self] type, eventType in
guard let self = self else { return }
if eventType == .cancel {
self.navigationController?.popViewController(animated: true)
return
}
if type == .link {
if eventType == .wechat {
let iconImg = UIImage(named: "shareIcon") ?? UIImage()
YHShareManager.shared.sendLinkContent("SB", "XXXXXXXX", iconImg, link: "www.baidu.com")
} else if eventType == .copyLink {
let pasteBoard = UIPasteboard.general
pasteBoard.string = ""
YHHUD.flash(message: "复制成功")
}
} else if type == .pdf {
if eventType == .wechat {
} else if eventType == .saveImg {
}
}
}
return v
}()
......
......@@ -128,7 +128,7 @@ class YHPlanViewController: YHBaseViewController {
}()
lazy var bgImgView: UIImageView = {
let v = UIImageView()
let v = UIImageView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenWidth))
v.image = UIImage(named: "plan_list_head_bg")
return v
}()
......@@ -299,11 +299,6 @@ class YHPlanViewController: YHBaseViewController {
self.view.addSubview(bottomView)
self.view.addSubview(whiteBackBtn)
self.view.addSubview(shareBtn)
bgImgView.snp.makeConstraints { make in
make.left.right.top.equalToSuperview()
make.height.equalTo(bgImgView.snp.width)
}
tableView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
......@@ -537,14 +532,17 @@ extension YHPlanViewController: UIScrollViewDelegate {
}
fakeTableView.isHidden = tableView.contentOffset.y <= topScrollHeight-1
if fakeTableView.contentOffset.y > 0 {
bgImgView.y = -scrollView.contentOffset.y-fakeTableView.contentOffset.y
bgImgView.y = -tableView.contentOffset.y-fakeTableView.contentOffset.y
} else {
bgImgView.y = -scrollView.contentOffset.y
bgImgView.y = -tableView.contentOffset.y
}
fakeTableView.isHidden = tableView.contentOffset.y <= topScrollHeight-1
if fakeTableView.contentOffset.y < -1 {
fakeTableView.contentOffset.y = -1
}
if tableView.contentOffset.y >= topScrollHeight, fakeTableView.contentOffset.y >= 0 {
tableView.isHidden = true
fakeTableView.isHidden = false
......
......@@ -129,8 +129,9 @@ class YHPlanLinkShareView: UIView {
clickBlock?(.saveImg)
} else if sender.tag == cancelTag {
dismiss()
}
dismiss()
}
@objc func show() {
......
......@@ -18,17 +18,17 @@ class YHPlanShareView: UIView {
var type: YHPlanShareBgType = .link {
didSet {
if type == .link {
copyLinkBtn.iconImgV.image = UIImage(named: "plan_share_copy")
copyLinkBtn.textLabel.text = "复制链接"
copyLinkBtn.isHidden = false
saveBtn.isHidden = true
} else if type == .pdf {
copyLinkBtn.iconImgV.image = UIImage(named: "plan_share_save")
copyLinkBtn.textLabel.text = "保存PDF"
copyLinkBtn.isHidden = true
saveBtn.isHidden = false
}
}
}
var clickBlock: ((YHPlanShareItemButtonType) -> Void)?
var clickBlock: ((YHPlanShareBgType, YHPlanShareItemButtonType) -> Void)?
lazy var whiteContentView: UIView = {
let v = UIView()
......@@ -67,18 +67,29 @@ class YHPlanShareView: UIView {
return v
}()
lazy var saveBtn: YHPlanShareItemButton = {
let v = YHPlanShareItemButton()
v.tag = saveImgTag
v.textLabel.text = "保存PDF"
v.iconImgV.image = UIImage(named: "plan_share_save")
v.isHidden = true
v.addTarget(self, action: #selector(didFunctionBtnClicked(_:)), for: .touchUpInside)
return v
}()
@objc func didFunctionBtnClicked(_ sender: UIButton) {
if sender.tag == wechatBtnTag {
clickBlock?(.wechat)
clickBlock?(type, .wechat)
} else if sender.tag == copyLinkTag {
clickBlock?(.copyLink)
clickBlock?(type, .copyLink)
} else if sender.tag == saveImgTag {
clickBlock?(.saveImg)
clickBlock?(type, .saveImg)
} else if sender.tag == cancelTag {
clickBlock?(type, .cancel)
}
}
......@@ -96,6 +107,7 @@ class YHPlanShareView: UIView {
self.addSubview(whiteContentView)
whiteContentView.addSubview(wechatBtn)
whiteContentView.addSubview(copyLinkBtn)
whiteContentView.addSubview(saveBtn)
whiteContentView.addSubview(cancelBtn)
whiteContentView.snp.makeConstraints { make in
......@@ -109,6 +121,12 @@ class YHPlanShareView: UIView {
make.left.equalTo(self.snp.centerX).offset(35)
}
saveBtn.snp.makeConstraints { make in
make.width.equalTo(64)
make.height.equalTo(74)
make.center.equalTo(copyLinkBtn)
}
wechatBtn.snp.makeConstraints { make in
make.width.equalTo(64)
make.height.equalTo(74)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment