Commit 395710ce authored by pete谢兆麟's avatar pete谢兆麟

通用分享弹窗

parent 82e140ce
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
04013E3C2CF86BB5001A8E40 /* YHSelectMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04013E3B2CF86BB5001A8E40 /* YHSelectMenuView.swift */; }; 04013E3C2CF86BB5001A8E40 /* YHSelectMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04013E3B2CF86BB5001A8E40 /* YHSelectMenuView.swift */; };
04013E3E2CF87F3A001A8E40 /* zhibo.json in Resources */ = {isa = PBXBuildFile; fileRef = 04013E3D2CF87F3A001A8E40 /* zhibo.json */; }; 04013E3E2CF87F3A001A8E40 /* zhibo.json in Resources */ = {isa = PBXBuildFile; fileRef = 04013E3D2CF87F3A001A8E40 /* zhibo.json */; };
04013E402CF99505001A8E40 /* live.json in Resources */ = {isa = PBXBuildFile; fileRef = 04013E3F2CF99505001A8E40 /* live.json */; }; 04013E402CF99505001A8E40 /* live.json in Resources */ = {isa = PBXBuildFile; fileRef = 04013E3F2CF99505001A8E40 /* live.json */; };
04013E422CFADF6B001A8E40 /* YHShareAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04013E412CFADF6B001A8E40 /* YHShareAlertView.swift */; };
040450CF2CC8A0F400D1CFE5 /* YHResignDocumentMultiLineTipsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 040450CE2CC8A0F400D1CFE5 /* YHResignDocumentMultiLineTipsCell.swift */; }; 040450CF2CC8A0F400D1CFE5 /* YHResignDocumentMultiLineTipsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 040450CE2CC8A0F400D1CFE5 /* YHResignDocumentMultiLineTipsCell.swift */; };
0408C3632BEC7C6900DB1E25 /* YHVideoPlayerControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0408C3622BEC7C6900DB1E25 /* YHVideoPlayerControlView.swift */; }; 0408C3632BEC7C6900DB1E25 /* YHVideoPlayerControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0408C3622BEC7C6900DB1E25 /* YHVideoPlayerControlView.swift */; };
0409BEEB2C5B41D4003FCFD7 /* YHPrincipleProfileListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0409BEEA2C5B41D4003FCFD7 /* YHPrincipleProfileListCell.swift */; }; 0409BEEB2C5B41D4003FCFD7 /* YHPrincipleProfileListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0409BEEA2C5B41D4003FCFD7 /* YHPrincipleProfileListCell.swift */; };
...@@ -1082,6 +1083,7 @@ ...@@ -1082,6 +1083,7 @@
04013E3B2CF86BB5001A8E40 /* YHSelectMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSelectMenuView.swift; sourceTree = "<group>"; }; 04013E3B2CF86BB5001A8E40 /* YHSelectMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSelectMenuView.swift; sourceTree = "<group>"; };
04013E3D2CF87F3A001A8E40 /* zhibo.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = zhibo.json; sourceTree = "<group>"; }; 04013E3D2CF87F3A001A8E40 /* zhibo.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = zhibo.json; sourceTree = "<group>"; };
04013E3F2CF99505001A8E40 /* live.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = live.json; sourceTree = "<group>"; }; 04013E3F2CF99505001A8E40 /* live.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = live.json; sourceTree = "<group>"; };
04013E412CFADF6B001A8E40 /* YHShareAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHShareAlertView.swift; sourceTree = "<group>"; };
040450CE2CC8A0F400D1CFE5 /* YHResignDocumentMultiLineTipsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResignDocumentMultiLineTipsCell.swift; sourceTree = "<group>"; }; 040450CE2CC8A0F400D1CFE5 /* YHResignDocumentMultiLineTipsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHResignDocumentMultiLineTipsCell.swift; sourceTree = "<group>"; };
0408C3622BEC7C6900DB1E25 /* YHVideoPlayerControlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHVideoPlayerControlView.swift; sourceTree = "<group>"; }; 0408C3622BEC7C6900DB1E25 /* YHVideoPlayerControlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHVideoPlayerControlView.swift; sourceTree = "<group>"; };
0409BEEA2C5B41D4003FCFD7 /* YHPrincipleProfileListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHPrincipleProfileListCell.swift; sourceTree = "<group>"; }; 0409BEEA2C5B41D4003FCFD7 /* YHPrincipleProfileListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHPrincipleProfileListCell.swift; sourceTree = "<group>"; };
...@@ -2991,6 +2993,7 @@ ...@@ -2991,6 +2993,7 @@
04564D552CF4467B004456E4 /* YHPlayerTopBarView.swift */, 04564D552CF4467B004456E4 /* YHPlayerTopBarView.swift */,
04564D5E2CF565C7004456E4 /* YHInputBottomBar.swift */, 04564D5E2CF565C7004456E4 /* YHInputBottomBar.swift */,
04564D7D2CF8D03D004456E4 /* YHFloatingWindow.swift */, 04564D7D2CF8D03D004456E4 /* YHFloatingWindow.swift */,
04013E412CFADF6B001A8E40 /* YHShareAlertView.swift */,
); );
path = V; path = V;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -6223,6 +6226,7 @@ ...@@ -6223,6 +6226,7 @@
0408C3632BEC7C6900DB1E25 /* YHVideoPlayerControlView.swift in Sources */, 0408C3632BEC7C6900DB1E25 /* YHVideoPlayerControlView.swift in Sources */,
042B20DF2CEB6A8F00655093 /* YHSchemeViewModel.swift in Sources */, 042B20DF2CEB6A8F00655093 /* YHSchemeViewModel.swift in Sources */,
044F394C2CB806D0007CA277 /* YHVisaRenewalPayMethodUrlCell.swift in Sources */, 044F394C2CB806D0007CA277 /* YHVisaRenewalPayMethodUrlCell.swift in Sources */,
04013E422CFADF6B001A8E40 /* YHShareAlertView.swift in Sources */,
A567E5B12BD7643D00D5D5A0 /* YHHomeCollectionViewCell.swift in Sources */, A567E5B12BD7643D00D5D5A0 /* YHHomeCollectionViewCell.swift in Sources */,
A582B2432BB95E20009D098C /* YHHKPlanCell.swift in Sources */, A582B2432BB95E20009D098C /* YHHKPlanCell.swift in Sources */,
04256DE62C7310BE00A37BA4 /* YHSelectApplicantGroupCell.swift in Sources */, 04256DE62C7310BE00A37BA4 /* YHSelectApplicantGroupCell.swift in Sources */,
......
...@@ -273,6 +273,7 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo ...@@ -273,6 +273,7 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
//跳转直播 文哥代办 //跳转直播 文哥代办
YHShareAlertView.show(image: "http://gips3.baidu.com/it/u=3886271102,3123389489&fm=3028&app=3028&f=JPEG&fmt=auto?w=1280&h=960", title: "12344", subMessage: "12213243", linkUrl: "https://www.baidu.com", isLive: true)
} }
} }
......
//
// YHShareAlertView.swift
// galaxy
//
// Created by EDY on 2024/11/30.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import AttributedString
import Photos
class YHShareAlertView: UIView {
var centerView: UIView!
var leftButton: YHShareButton!
var centerButton: YHShareButton!
var rightButton: YHShareButton!
var cannalButton: UIButton!
var tableView: UITableView!
var shareView: UIImageView!
var mainImageView: UIImageView!
var titleLabel: UILabel!
var messageLabel: UILabel!
var bottomView: UIImageView!
var bottomTitleLabel: UILabel!
var flagImageView: UIImageView!
var liveView: UIImageView!
var image: String = "" {
didSet {
mainImageView.kf.setImage(with: URL(string: image))
}
}
var title: String = "" {
didSet {
titleLabel.text = title
}
}
var subMessage: String = "" {
didSet {
messageLabel.text = subMessage
}
}
var linkUrl: String = "" {
didSet {
let qrString = linkUrl
if let qrCode = qrString.generateQRCode() {
// 可以将qrCode设置为UIImageView的image属性来显示二维码
flagImageView.image = qrCode
}
}
}
var isLive: Bool = false {
didSet {
liveView.isHidden = !isLive
}
}
var dataSource: [String] = [] {
didSet {
self.tableView.reloadData()
}
}
var selectItem: Int = 10000
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(white: 0.5, alpha: 0.1)
let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
tap.delegate = self
addGestureRecognizer(tap)
setView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setView() {
backgroundColor = UIColor(hex: 0x0000, alpha: 0.5)
centerView = {
let view = UIView()
view.backgroundColor = .white
return view
}()
addSubview(centerView)
centerView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.height.equalTo(216)
}
leftButton = {
let button = YHShareButton()
button.setContent("invitation_with_gifts_share_center", "微信")
button.addTarget(self, action: #selector(wxClick), for: .touchUpInside)
return button
}()
centerView.addSubview(leftButton)
leftButton.snp.makeConstraints { make in
make.top.equalTo(20)
make.left.equalTo(42)
make.height.equalTo(74)
make.width.equalTo(52)
}
centerButton = {
let button = YHShareButton()
button.setContent("invitation_with_gifts_share_link", "复制链接")
button.addTarget(self, action: #selector(linkClick), for: .touchUpInside)
return button
}()
centerView.addSubview(centerButton)
centerButton.snp.makeConstraints { make in
make.top.equalTo(20)
make.centerX.equalToSuperview()
make.height.equalTo(74)
make.width.equalTo(52)
}
rightButton = {
let button = YHShareButton()
button.setContent("invitation_with_gifts_share_save", "保存图片")
button.addTarget(self, action: #selector(saveClick), for: .touchUpInside)
return button
}()
centerView.addSubview(rightButton)
rightButton.snp.makeConstraints { make in
make.top.equalTo(20)
make.right.equalTo(-42)
make.height.equalTo(74)
make.width.equalTo(52)
}
cannalButton = {
let button = UIButton(type: .custom)
button.backgroundColor = UIColor.contentBkgColor
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 15)
button.contentHorizontalAlignment = .center
button.setTitle("取消", for: .normal)
button.setTitleColor( UIColor.mainTextColor, for: .normal)
button.layer.cornerRadius = kCornerRadius3
button.addTarget(self, action: #selector(dismiss), for: .touchUpInside)
return button
}()
centerView.addSubview(cannalButton)
cannalButton.snp.makeConstraints { make in
make.left.equalTo(16)
make.top.equalTo(126)
make.height.equalTo(44)
make.right.equalTo(16)
}
shareView = {
let view = UIImageView()
view.backgroundColor = .white
return view
}()
addSubview(shareView)
shareView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.height.equalTo(432)
make.width.equalTo(271)
make.bottom.equalTo(centerView.snp.top).offset(-67)
}
mainImageView = {
let view = UIImageView()
return view
}()
shareView.addSubview(mainImageView)
mainImageView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.width.height.equalTo(239)
make.top.equalTo(16)
}
titleLabel = {
let label = UILabel()
label.textColor = UIColor.mainTextColor
label.font = UIFont.PFSC_M(ofSize: 15)
label.text = "香港事业星陪伴(7)"
return label
}()
shareView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.top.equalTo(mainImageView.snp.bottom).offset(16)
make.left.equalTo(16)
make.right.equalTo(16)
}
messageLabel = {
let label = UILabel()
label.textColor = UIColor(hex: 0x6d788a)
label.font = UIFont.PFSC_M(ofSize: 12)
label.text = "香港入境计划申请到永居全流程服务)"
label.numberOfLines = 2
return label
}()
shareView.addSubview(messageLabel)
messageLabel.snp.makeConstraints { make in
make.top.equalTo(titleLabel.snp.bottom).offset(6)
make.left.equalTo(16)
make.right.equalTo(16)
}
bottomView = {
let view = UIImageView()
view.image = UIImage(named: "invitation_with_gifts_share_bg_bottom")
return view
}()
shareView.addSubview(bottomView)
bottomView.snp.makeConstraints { make in
make.bottom.left.right.equalToSuperview()
make.height.equalTo(92)
}
bottomTitleLabel = {
let label = UILabel()
label.numberOfLines = 0
let a: ASAttributedString = .init("银河", .font(UIFont.PFSC_R(ofSize: 13)),.foreground(UIColor.mainTextColor))
let b: ASAttributedString = .init("港生活\n", .font(UIFont.PFSC_R(ofSize: 14)),.foreground(UIColor.brandMainColor))
let c: ASAttributedString = .init("美好新生活从这里开始", .font(UIFont.PFSC_R(ofSize: 10)),.foreground(UIColor(hex: 0x8993a2)))
label.attributed.text = a + b + c
return label
}()
bottomView.addSubview(bottomTitleLabel)
bottomTitleLabel.snp.makeConstraints { make in
make.bottom.equalTo(-20)
make.left.equalTo(16)
make.right.equalTo(-16)
}
flagImageView = {
let view = UIImageView()
return view
}()
bottomView.addSubview(flagImageView)
flagImageView.snp.makeConstraints { make in
make.right.equalTo(-16)
make.width.height.equalTo(72)
make.bottom.equalTo(-16)
}
liveView = {
let view = UIImageView()
view.image = UIImage(named: "invitation_with_gifts_share_live")
return view
}()
mainImageView.addSubview(liveView)
liveView.snp.makeConstraints { make in
make.left.equalTo(10)
make.bottom.equalTo(-12)
make.height.equalTo(16)
make.width.equalTo(51)
}
centerView.layoutIfNeeded()
let corner = UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue)
let path = UIBezierPath(roundedRect:bounds,byRoundingCorners: corner,cornerRadii:CGSizeMake(kCornerRadius6, kCornerRadius6))
let layer = CAShapeLayer()
layer.frame = centerView.bounds
layer.path = path.cgPath
centerView.layer.mask = layer
}
@objc private func handleTap(_ sender: AnyObject?) {
dismiss()
}
static func show(image: String = "", title: String = "", subMessage: String = "", linkUrl: String = "", isLive: Bool = false) {
let view = YHShareAlertView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight))
view.image = image
view.title = title
view.subMessage = subMessage
view.linkUrl = linkUrl
view.isLive = isLive
let window = UIApplication.shared.yhKeyWindow()
window?.addSubview(view)
}
@objc func dismiss() {
removeFromSuperview()
}
@objc func saveClick() {
guard let combinedImage = combinedImageFrom(imageView: shareView) else { return }
saveImageToPhotosAlbum(image: combinedImage)
}
@objc func linkClick() {
let textToCopy = linkUrl
UIPasteboard.general.string = textToCopy
YHHUD.flash(message: "复制成功")
}
@objc func wxClick() {
YHShareManager.shared.sendLinkContent("香港身份规划专属礼包,限时领取!", "1000元折扣福利券,资深银河规划专家1V1评估方案", UIImage(named: "invitation_with_gifts_share_other") ?? UIImage(), link: YHBaseUrlManager.shared.curH5URL() + "superAppBridge.html#/evaluation?channel=lkhtj-app&customer_id=\(YHLoginManager.shared.userModel?.id ?? "")&scene_id=30")
}
func saveImageToPhotosAlbum(image: UIImage) {
// 确保应用有权访问相册
PHPhotoLibrary.requestAuthorization { status in
if status == .authorized {
// 保存图片到相册
DispatchQueue.main.async {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
YHHUD.flash(message: "保存成功")
}
} else {
DispatchQueue.main.async {
YHHUD.flash(message: "保存失败,请检查系统权限")
}
}
}
}
func combinedImageFrom(imageView: UIImageView) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, 0.0)
// 首先绘制 imageView 的内容
imageView.layer.render(in: UIGraphicsGetCurrentContext()!)
// 获取合成后的图像
let combinedImage = UIGraphicsGetImageFromCurrentImageContext()
// 结束绘图上下文
UIGraphicsEndImageContext()
return combinedImage
}
}
extension YHShareAlertView: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer:UIGestureRecognizer, shouldReceive touch:UITouch) -> Bool {
if touch.view == self {
return true
}
return false
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "invitation_with_gifts_share_bg_bottom@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "invitation_with_gifts_share_bg_bottom@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "invitation_with_gifts_share_link@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "invitation_with_gifts_share_link@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "invitation_with_gifts_share_live@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "invitation_with_gifts_share_live@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "invitation_with_gifts_share_save@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "保存图片.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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